gpt4 book ai didi

c# - UWP 写入 InstalledLocation 获取访问被拒绝

转载 作者:太空宇宙 更新时间:2023-11-03 19:40:12 25 4
gpt4 key购买 nike

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

有趣的是我可以很好地读取文件。然后,当我测试写入它时,我得到了错误。

我使用记事本在那里创建了 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");

我尝试修改 list 以启用 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>

最佳答案

这是设计使然。安装位置是写保护的,以确保安装的完整性并允许增量更新和完全卸载。

您应该改为写入您的 ApplicationData。
https://learn.microsoft.com/en-us/windows/uwp/design/app-settings/store-and-retrieve-app-data

关于c# - UWP 写入 InstalledLocation 获取访问被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54543781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com