Click here to Skip to main content
16,013,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my project. I created a file in folder "Data/history.txt". I can access history.txt to read somethings from it, by using code:
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Data/history.txt"));
StreamReader reader = new StreamReader(await file.OpenStreamForReadAsync());
while (!reader.EndOfStream)
{
string s = reader.ReadLine();
}

but I can't write any thing to this file, by using code:
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Data/history.txt"));
await Windows.Storage.FileIO.AppendTextAsync(file, text + '\n');

After build, I received an info about access file:
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
If you are attempting to access a file or registry key, make sure it is not read-only.
Make sure you have sufficient privileges to access this resource...

Can anyone help me, plz??
Thanks for your time!!
Posted

1 solution

What part of "Access Denied" is difficult to understand?? You better read up on the various locations and what they're for in Windows Store apps, here[^].

The path you specified is under the application install location, which is always READ ONLY. You can't write data to this location. You have to use a more user-friendly (as far as security is concerned) location to write your data, like "ms-appdata:///".
 
Share this answer
 
Comments
askersuku 28-Feb-13 7:56am    
It works! thank you very much!
it's ms-appdata ^^
askersuku 28-Feb-13 7:59am    
But, you can show me, file is created in ms-appdata, where its location from project? I don't know ^^
Dave Kreskowiak 28-Feb-13 10:06am    
Read the damn link I put in my post. I'm not going to spoon feed you every little detail about this. Documentation exists for a reason!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900