Answered by:
Cant we access the txt file in the assets folder?

Question
-
Hi,
I am developing a windows store app. I am storing a txt file in "Assets" folder. I am able to read the contents in it using
var assetFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets") var file = await assetFolder.GetFileAsync("<filename">);
But am not able to write anything into it. i.e., writeLinesAsync is throwing me "Access Denied exception". So don't we get a read/write access to such files in the installed location??
Thanks In Advance
Friday, October 4, 2013 9:41 AM
Answers
-
Hello Rajesh,
For Copy file from installed folder to local folder than this code help to you:
async void CopyPrayerFile() { //get the storage for your app Windows.Storage.StorageFolder store = Windows.Storage.ApplicationData.Current.LocalFolder; StorageFile prayerFile = null; try { prayerFile = await store.GetFileAsync("Your file name"); } catch (System.IO.FileNotFoundException) {} if (prayerFile == null) { StorageFolder install = Windows.ApplicationModel.Package.Current.InstalledLocation; StorageFile installFile = await install.GetFileAsync("your file name"); installFile.CopyAsync(store); } }
- Proposed as answer by Ahmed-Fouad Friday, October 4, 2013 11:13 PM
- Unproposed as answer by Ahmed-Fouad Saturday, October 5, 2013 12:56 AM
- Marked as answer by Anne Jing Thursday, October 10, 2013 9:17 AM
Friday, October 4, 2013 4:54 PM
All replies
-
Hello Rajesh,
You can't write file in apps installed location because, the app's installed directory is a read-only. For more information Show this document:
http://msdn.microsoft.com/en-us/library/windows/apps/hh967755.aspx
- Edited by Khant Nipun Friday, October 4, 2013 10:55 AM
Friday, October 4, 2013 10:16 AM -
Above link is not working. Anyways are u sure about it? Cant we write into those files?Friday, October 4, 2013 10:44 AM
-
Hello Rajesh,
Yes i am sure about it. I edit this link. Check this link.
Friday, October 4, 2013 10:56 AM -
As a best practice you should copy file from your package to local or temp directory. Then you will have full access to it.Friday, October 4, 2013 1:38 PM
-
Hello Rajesh,
For Copy file from installed folder to local folder than this code help to you:
async void CopyPrayerFile() { //get the storage for your app Windows.Storage.StorageFolder store = Windows.Storage.ApplicationData.Current.LocalFolder; StorageFile prayerFile = null; try { prayerFile = await store.GetFileAsync("Your file name"); } catch (System.IO.FileNotFoundException) {} if (prayerFile == null) { StorageFolder install = Windows.ApplicationModel.Package.Current.InstalledLocation; StorageFile installFile = await install.GetFileAsync("your file name"); installFile.CopyAsync(store); } }
- Proposed as answer by Ahmed-Fouad Friday, October 4, 2013 11:13 PM
- Unproposed as answer by Ahmed-Fouad Saturday, October 5, 2013 12:56 AM
- Marked as answer by Anne Jing Thursday, October 10, 2013 9:17 AM
Friday, October 4, 2013 4:54 PM