Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
830 views
in Technique[技术] by (71.8m points)

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

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(@"Pathofolder");

// This line works only after I add a pdf file type association.
StorageFile file = await StorageFile.GetFileFromPathAsync(@"Pathofile.pdf");
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...