UWP写InstalledLocation被访问被拒绝

问题描述 投票:0回答:2

我收到“访问被拒绝”当我尝试在应用程序的安装目录中的文件夹内写入文件。

有趣的是,我可以读取该文件就好了。然后,当我试写它,我得到的错误。

我用记事本有创建sample.txt的文件。

目标:

这样做的原因是,所以我的Windows窗体应用程序可以与UWP应用程序交换文件。我需要做的是,Windows应用程序可以找到一个文件夹中的交流;被固定(恒定)。不过,我觉得也许是UWP安装文件夹会工作。

这个应用到我们的产品,而不是“存储” - 没有外部连接。理想情况下,我想完全进入到Windows 10。

这里是我的UWP C#测试代码.... enter image description here

下面是相同的代码,只是一切都非常喜欢...

   StorageFolder mobile_upload_StorageFolder=null;

StorageFolder app_installedLocation_StorageFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;

string mobile_folder_name =               "FOR_MOBILE_UPLOAD";
 mobile_upload_StorageFolder = await app_installedLocation_StorageFolder.CreateFolderAsync(mobile_folder_name, CreationCollisionOption.OpenIfExists  );
Windows.Storage.StorageFile sampleFile = await mobile_upload_StorageFolder.GetFileAsync("sample.txt");

string text = await Windows.Storage.FileIO.ReadTextAsync(sampleFile);
Debug.WriteLine( "text: " +  text );
 await Windows.Storage.FileIO.WriteTextAsync(sampleFile, "WRITTEN BY UWP");

我试图修改清单,使broadFileSystemAccess但得到以下错误... ...。

    <?xml version="1.0" encoding="utf-8"?>
<Package xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp uap5">
    xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
    IgnorableNamespaces="uap mp uap5 rescap">

    <Identity Name="Microsoft.SDKSamples.CameraFrames.CS" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" Version="1.0.0.0" />
  <mp:PhoneIdentity PhoneProductId="2344b9de-5071-42a6-8873-7fdeb38d53dd" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
  <Properties>
    <DisplayName>Camera Frames C# Sample</DisplayName>
    <PublisherDisplayName>Microsoft Corporation</PublisherDisplayName>
    <Logo>Assets\StoreLogo-sdk.png</Logo>
  </Properties>
  <Dependencies>
    <TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.15063.0" MaxVersionTested="10.0.17134.0" />
  </Dependencies>
  <Resources>
    <Resource Language="x-generate" />
  </Resources>
  <Applications>
    <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="CameraFrames.App">
      <uap:VisualElements DisplayName="MOVANO System Hub Camera  interface" Square150x150Logo="Assets\SquareTile-sdk.png" Square44x44Logo="Assets\SmallTile-sdk.png" Description="Camera Frames C# Sample" BackgroundColor="#00b2f0">
        <uap:SplashScreen Image="Assets\Splash-sdk.png" />
        <uap:DefaultTile>
          <uap:ShowNameOnTiles>
            <uap:ShowOn Tile="square150x150Logo" />
          </uap:ShowNameOnTiles>
        </uap:DefaultTile>
      </uap:VisualElements>
    </Application>
  </Applications>
  <Capabilities>
    <rescap:Capability Name="broadFileSystemAccess" />  CAUSES "the 'name' attribute is not valid"
    <Capability Name="privateNetworkClientServer" />
    <Capability Name="internetClientServer" />
    <DeviceCapability Name="microphone" />
    <DeviceCapability Name="webcam" />
  </Capabilities>
</Package>
c# visual-studio uwp
2个回答
4
投票

这是由设计。安装位置被写保护,以保证安装的完整性,并允许增量更新以及卸载干净。

你应当写信给你的ApplicationData代替。 https://docs.microsoft.com/en-us/windows/uwp/design/app-settings/store-and-retrieve-app-data


1
投票

这是没有什么有趣的,这是每一个操作系统(至少每一个主要的,如Windows,MacOS的,iOS版,Android版)是如何工作的。当然,你可能在某些操作系统上的某些情况下,如果你是管理员,有时甚至有一些额外的preveliges,但基本上,用户不能做正确写入到每个文件夹,即使在限制较少的环境比UWP(如WPF或者MacOS) 。

如果用户通过使用一些文件系统选择器来访问该文件夹你可能会问的权利。你也可以在你的清单索要broadFileSystemAccess,你将有访问该用户可以访问所有文件夹。但问题仍然存在作为一般用户不能访问UWP安装文件夹没有一些额外的分配权利。

所以,你应该考虑在其他地方写你的数据。

© www.soinside.com 2019 - 2024. All rights reserved.