PrOgrAMmer PrOgrAMmer - 20 days ago 5x
C# Question

Exception thrown: 'System.UnauthorizedAccessException' in 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 ("Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))") 0.24s [13604] Worker Thread

I have set these capabilities:

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

Where is the problem:


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


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