PrOgrAMmer PrOgrAMmer - 2 months ago 22
C# Question

Exception thrown: 'System.UnauthorizedAccessException' in mscorlib.ni.dll uwp

i Go the above error and i don't know why, when i called CreateFolderAsync()

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

StorageFolder newFolder = await appInstalledFolder.CreateFolderAsync(ClientFolder, CreationCollisionOption.ReplaceExisting);


Activated Event Time Duration Thread
Exception thrown: 'System.UnauthorizedAccessException' in mscorlib.ni.dll ("Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))") 0.24s [13604] Worker Thread


I have set these capabilities:

<Capabilities>
<Capability Name="internetClient" />
<uap:Capability Name="removableStorage" />
</Capabilities>


Where is the problem:

Answer

Not use Windows.ApplicationModel.Package.Current.You can use

ApplicationData.Current.LocalFolder;

ApplicationData.Current have LocalFolder and LocalCache and the tempUse file or folder can put in LoacalCache and the AppData can write in LocalFolder.

If you need use the Users file or folder,you can use the FolderPicker or FilePicker to pick the folder and file.

The StorageApplicationPermissions.FutureAccessList can remember the users folder and file ,but it should use token.

You can see https://msdn.microsoft.com/zh-cn/windows/uwp/files/quickstart-reading-and-writing-files

Comments