如何解决使用 UWP GetFolderFromPathAsync 时访问被拒绝的问题
how to solve access denied when using UWP GetFolderFromPathAsync
尝试使用 GetFolderFromPathAsync 从我的 UWP 应用程序访问文件系统时,访问被拒绝。
我的 UWP 应用程序需要访问 Windows 10 文件系统。
我正在使用 broadFileSystemAccess 但卡住了。
我下面的代码在执行 GetFolderFromPathAsync 时得到 "access denied"。
当我尝试设置清单文件类型时,出现以下错误。
非常感谢任何帮助。
我的代码
StorageFolder test_StorageFolder = await StorageFolder.GetFolderFromPathAsync(@"C:\demo");
StorageFile sampleFile = await test_StorageFolder.CreateFileAsync("test.txt",
Windows.Storage.CreationCollisionOption.ReplaceExisting);
我的明显错误...
Validation error. error C00CE020: App manifest validation error: The
app manifest must be valid as per schema: Line 43, Column 12, Reason:
Required attribute 'Name' is missing.
我的清单...
I.E...
> <?xml version="1.0" encoding="utf-8"?> <Package
> xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
> xmlns="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 build"
> xmlns:build="http://schemas.microsoft.com/developer/appx/2015/build">
> <!--
> THIS PACKAGE MANIFEST FILE IS GENERATED BY THE BUILD PROCESS.
>
> Changes to this file will be lost when it is regenerated. To correct errors in this file, edit the source .appxmanifest file.
>
> For more information on package manifest files, see http://go.microsoft.com/fwlink/?LinkID=241727 --> <Identity
> Name="Microsoft.SDKSamples.CameraFrames.CS" Publisher="CN=Microsoft
> Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US"
> Version="1.0.0.0" ProcessorArchitecture="x64" /> <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.17134.0" MaxVersionTested="10.0.17134.0" />
> </Dependencies> <Resources>
> <Resource Language="EN-US" /> </Resources> <Applications>
> <Application Id="App" Executable="CameraFrames.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>
> <Extensions>
> <uap:Extension Category="windows.fileTypeAssociation">
> <uap:FileTypeAssociation Name="access">
> <uap:SupportedFileTypes>
> <uap:FileType>.txt</uap:FileType>
> <uap:FileType>.bin</uap:FileType>
> </uap:SupportedFileTypes>
> </uap:FileTypeAssociation>
> </uap:Extension>
> <uap:Extension Category="windows.fileTypeAssociation">
> <uap:FileTypeAssociation>
> <uap:SupportedFileTypes>
> <uap:FileType></uap:FileType>
> </uap:SupportedFileTypes>
> </uap:FileTypeAssociation>
> </uap:Extension>
> </Extensions>
> </Application> </Applications> <Capabilities>
> <Capability Name="privateNetworkClientServer" />
> <Capability Name="internetClientServer" />
> <DeviceCapability Name="microphone" />
> <DeviceCapability Name="webcam" /> </Capabilities> <build:Metadata>
> <build:Item Name="TargetFrameworkMoniker" Value=".NETCore,Version=v5.0" />
> <build:Item Name="VisualStudio" Version="15.0" />
> <build:Item Name="VisualStudioEdition" Value="Microsoft Visual Studio Professional 2017" />
> <build:Item Name="OperatingSystem" Version="10.0.17134.1 (WinBuild.160101.0800)" />
> <build:Item Name="Microsoft.Build.AppxPackage.dll" Version="15.0.28307.104" />
> <build:Item Name="ProjectGUID" Value="{1BF84D6E-9DCE-5653-AC51-BB4FC694A252}" />
> <build:Item Name="OptimizingToolset" Value="None" />
> <build:Item Name="TargetRuntime" Value="Managed" />
> <build:Item Name="Microsoft.Windows.UI.Xaml.Build.Tasks.dll" Version="15.0.28307.102" />
> <build:Item Name="MakePri.exe" Version="10.0.17134.12 (WinBuild.160101.0800)" /> </build:Metadata> </Package>
我向 Microsoft 技术支持支付了 500 美元并得到了 'secret' 答复。在这里,我的程序员们...
- 打开项目文件夹
- 删除 .vs 文件夹。
- 删除 bin 和 obj
- 打开解决方案
- 清洁溶液
- 右键单击解决方案 -> 恢复 NuGet 包
- 打开项目清单代码(非 GUI)
改变
IgnorableNamespaces="uap mp">
至
IgnorableNamespaces="uap mp rescap">
替换
<DeviceCapability xmlns:rescap=http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities
与
<rescap:Capability Name="broadFileSystemAccess"/>
Build > Config Manager > Active solution platform = x64(默认为 ARM)
- 重建解决方案
- 构建 > 部署
- Window 按钮 > 搜索:文件系统隐私设置
- 启用您的应用程序
一切顺利。
尝试使用 GetFolderFromPathAsync 从我的 UWP 应用程序访问文件系统时,访问被拒绝。
我的 UWP 应用程序需要访问 Windows 10 文件系统。 我正在使用 broadFileSystemAccess 但卡住了。 我下面的代码在执行 GetFolderFromPathAsync 时得到 "access denied"。
当我尝试设置清单文件类型时,出现以下错误。
非常感谢任何帮助。
我的代码
StorageFolder test_StorageFolder = await StorageFolder.GetFolderFromPathAsync(@"C:\demo");
StorageFile sampleFile = await test_StorageFolder.CreateFileAsync("test.txt",
Windows.Storage.CreationCollisionOption.ReplaceExisting);
我的明显错误...
Validation error. error C00CE020: App manifest validation error: The app manifest must be valid as per schema: Line 43, Column 12, Reason: Required attribute 'Name' is missing.
我的清单...
I.E...
> <?xml version="1.0" encoding="utf-8"?> <Package
> xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
> xmlns="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 build"
> xmlns:build="http://schemas.microsoft.com/developer/appx/2015/build">
> <!--
> THIS PACKAGE MANIFEST FILE IS GENERATED BY THE BUILD PROCESS.
>
> Changes to this file will be lost when it is regenerated. To correct errors in this file, edit the source .appxmanifest file.
>
> For more information on package manifest files, see http://go.microsoft.com/fwlink/?LinkID=241727 --> <Identity
> Name="Microsoft.SDKSamples.CameraFrames.CS" Publisher="CN=Microsoft
> Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US"
> Version="1.0.0.0" ProcessorArchitecture="x64" /> <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.17134.0" MaxVersionTested="10.0.17134.0" />
> </Dependencies> <Resources>
> <Resource Language="EN-US" /> </Resources> <Applications>
> <Application Id="App" Executable="CameraFrames.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>
> <Extensions>
> <uap:Extension Category="windows.fileTypeAssociation">
> <uap:FileTypeAssociation Name="access">
> <uap:SupportedFileTypes>
> <uap:FileType>.txt</uap:FileType>
> <uap:FileType>.bin</uap:FileType>
> </uap:SupportedFileTypes>
> </uap:FileTypeAssociation>
> </uap:Extension>
> <uap:Extension Category="windows.fileTypeAssociation">
> <uap:FileTypeAssociation>
> <uap:SupportedFileTypes>
> <uap:FileType></uap:FileType>
> </uap:SupportedFileTypes>
> </uap:FileTypeAssociation>
> </uap:Extension>
> </Extensions>
> </Application> </Applications> <Capabilities>
> <Capability Name="privateNetworkClientServer" />
> <Capability Name="internetClientServer" />
> <DeviceCapability Name="microphone" />
> <DeviceCapability Name="webcam" /> </Capabilities> <build:Metadata>
> <build:Item Name="TargetFrameworkMoniker" Value=".NETCore,Version=v5.0" />
> <build:Item Name="VisualStudio" Version="15.0" />
> <build:Item Name="VisualStudioEdition" Value="Microsoft Visual Studio Professional 2017" />
> <build:Item Name="OperatingSystem" Version="10.0.17134.1 (WinBuild.160101.0800)" />
> <build:Item Name="Microsoft.Build.AppxPackage.dll" Version="15.0.28307.104" />
> <build:Item Name="ProjectGUID" Value="{1BF84D6E-9DCE-5653-AC51-BB4FC694A252}" />
> <build:Item Name="OptimizingToolset" Value="None" />
> <build:Item Name="TargetRuntime" Value="Managed" />
> <build:Item Name="Microsoft.Windows.UI.Xaml.Build.Tasks.dll" Version="15.0.28307.102" />
> <build:Item Name="MakePri.exe" Version="10.0.17134.12 (WinBuild.160101.0800)" /> </build:Metadata> </Package>
我向 Microsoft 技术支持支付了 500 美元并得到了 'secret' 答复。在这里,我的程序员们...
- 打开项目文件夹
- 删除 .vs 文件夹。
- 删除 bin 和 obj
- 打开解决方案
- 清洁溶液
- 右键单击解决方案 -> 恢复 NuGet 包
- 打开项目清单代码(非 GUI)
改变
IgnorableNamespaces="uap mp">
至
IgnorableNamespaces="uap mp rescap">
替换
<DeviceCapability xmlns:rescap=http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities
与<rescap:Capability Name="broadFileSystemAccess"/>
Build > Config Manager > Active solution platform = x64(默认为 ARM)
- 重建解决方案
- 构建 > 部署
- Window 按钮 > 搜索:文件系统隐私设置
- 启用您的应用程序
一切顺利。