Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't read/write files when using UWP broadFileSystemAccess restricted permission

Tags:

c#

uwp

I'm building an internal company app and trying to read and write files on local and network drives. I have added the broadFileSystemAccess restricted capability. I am able to list directories, but I get System.UnauthorizedAccessException when trying to read or write any files.

I have found that if I also add file type associations for the types of files I am reading or writing, then it works. However, this also means that the app gets registered with Windows to open those file types, which I do not want.

// This line works once I enable broadFileSystemAccess.
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(@"Path\to\folder");

// This line works only after I add a pdf file type association.
StorageFile file = await StorageFile.GetFileFromPathAsync(@"Path\to\file.pdf");
like image 966
Trygve Avatar asked Feb 02 '26 10:02

Trygve


1 Answers

As Stefan Wick MSFT said, after add broadFileSystemAccess capability, you also need to manually enable broad file system in File System setting page. For getting the setting page, you could search file system keywords in setting app home page.

enter image description here

like image 153
Nico Zhu - MSFT Avatar answered Feb 05 '26 01:02

Nico Zhu - MSFT