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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…