Answered by:
Accessing File from a random folder

Question
-
I am getting unauthorized access exception when i try to access a file
File.ReadAllBytes(file in document library) located in documents.
I am not able to access file in any folder any resolution to it, or it is windows 8 property
- Edited by Panthera_uncia Friday, March 11, 2016 12:37 PM
Friday, March 11, 2016 12:28 PM
Answers
-
and you can use
var file = await KnownFolders.PicturesLibrary.GetFileAsync("filename"); using (Stream s = await file.OpenStreamForReadAsync()) { }
Microsoft Certified Solutions Developer - Windows Store Apps Using C#
- Proposed as answer by Active Geometry Monday, March 21, 2016 5:20 AM
- Marked as answer by Barry Wang Wednesday, March 23, 2016 1:45 AM
Friday, March 11, 2016 12:44 PM -
as soon youi have the StorageFile instance you are good to go. So if the user uses e FIleOpenPicker to give your app a file from e:\ you are good. You cant say File.Read("E:\file") you need the storagefile class for this
Microsoft Certified Solutions Developer - Windows Store Apps Using C#
- Proposed as answer by Active Geometry Monday, March 21, 2016 5:20 AM
- Marked as answer by Barry Wang Wednesday, March 23, 2016 1:45 AM
Friday, March 11, 2016 12:53 PM
All replies
-
where is that file coming from ? you can't randomly access files. what is attchDetail ?
Microsoft Certified Solutions Developer - Windows Store Apps Using C#
Friday, March 11, 2016 12:30 PM -
File is in any folder like Documens, Picture or Music library, I need to get bytes of file.Friday, March 11, 2016 12:40 PM
-
for the libraries you need to set the permissions in the manifest file
Microsoft Certified Solutions Developer - Windows Store Apps Using C#
Friday, March 11, 2016 12:42 PM -
and you can use
var file = await KnownFolders.PicturesLibrary.GetFileAsync("filename"); using (Stream s = await file.OpenStreamForReadAsync()) { }
Microsoft Certified Solutions Developer - Windows Store Apps Using C#
- Proposed as answer by Active Geometry Monday, March 21, 2016 5:20 AM
- Marked as answer by Barry Wang Wednesday, March 23, 2016 1:45 AM
Friday, March 11, 2016 12:44 PM -
Scenario is where file picker can select any file from system and that file is to be converted to byte array.
So known folder is of little use.- Edited by Panthera_uncia Friday, March 11, 2016 12:52 PM
Friday, March 11, 2016 12:51 PM -
as soon youi have the StorageFile instance you are good to go. So if the user uses e FIleOpenPicker to give your app a file from e:\ you are good. You cant say File.Read("E:\file") you need the storagefile class for this
Microsoft Certified Solutions Developer - Windows Store Apps Using C#
- Proposed as answer by Active Geometry Monday, March 21, 2016 5:20 AM
- Marked as answer by Barry Wang Wednesday, March 23, 2016 1:45 AM
Friday, March 11, 2016 12:53 PM