【发布时间】:2019-02-05 22:05:23
【问题描述】:
当我尝试写入应用程序安装目录中的文件夹中的文件时,我收到“访问被拒绝”。
有趣的是我可以很好地阅读文件。然后,当我测试写入它时,我得到了错误。
我使用 NOTEPAD 在那里创建了 sample.txt 文件。
目标:
这样做的原因是我的 Windows 窗体应用程序可以与 UWP 应用程序交换文件。我需要在 Windows 应用程序可以找到的文件夹中进行交换;这是固定的(常数)。我虽然也许 uwp 安装文件夹可以工作。
这个应用程序进入我们的产品,而不是“商店”——没有外部连接。理想情况下,我希望完全访问 Windows 10。
这是相同的代码,只是非常像......
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