c# - UnAuthorizedAccessException on StorageFolder.GetFolderFromPathAsync while having access through FilePicker -
i try read files network location. keep getting unauthorizedaccessexception.
i pick storagefolder through storagefolder.getfolderfrompathasync listing files throws exception.
when pick same folder through folderpicker works.
so tried pinpointing problem code:
folderpicker picker = new folderpicker(); picker.filetypefilter.add("*"); storagefolder pickedfolder = await picker.picksinglefolderasync(); if (pickedfolder != null) { var pickedfolderlist = await pickedfolder.getfilesasync(); var count = pickedfolderlist.count; if (count > 0) { storagefolder folder = await storagefolder.getfolderfrompathasync(pickedfolder.path); var pathfolderlist = await folder.getfilesasync(); //exception if (pathfolderlist.count == count) { processfolder(folder); } } }
the exception thrown @ marked line variable pathfolderlist set. while had listed same folder few lines above.
i have set these capabilities:
<capabilities> <capability name="internetclient" /> <capability name="privatenetworkclientserver"/> <uap:capability name="enterpriseauthentication"/> <uap:capability name="removablestorage"/> </capabilities>
what missing?
your app doesn't have access path. permission access file handled via storagefolder returned picker.
instead of line try create new storagefolder pickedfolder
storagefolder folder = await storagefolder.getfolderfrompathasync(pickedfolder.path);
just use pickedfolder itself:
var pathfolderlist = await pickedfolder.getfilesasync(); //exception
i went in more detail in blog entry skip path: stick storagefile
Comments
Post a Comment