Click here to Skip to main content
15,888,020 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I read a xml file from assets. Now I want to replace modify xml file, but when I want to wirte in xml file throwing exception:

An exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll but was not handled in user code

Additional information: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

I can write xml file in C:\Users\Sergiu\Documents, but I want to write xml file in Assets folder from project.

C#
 private async void CreateFILE(string file_name)
        {
             
           folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets");
           
            sampleFile = await folder.CreateFileAsync(file_name, CreationCollisionOption.OpenIfExists);

        }
        private async void WriteFILE()
        {
           await Windows.Storage.FileIO.WriteTextAsync(sampleFile, xml_file); 
//here throw exception          
// xml_file is xml file contain
string xml_file = @"<?xml version=""1.0"" encoding=""utf-8"" ?>\n<Players>\n";
//...
xml_file+="</Players>";
        }
Posted
Comments
Richard MacCutchan 3-May-14 9:49am    
Change the access level for this folder or run under admin privilege.
Mercas Sergiu 3-May-14 10:42am    
I try to change the acess level(inclusively in command prompt run as admin), but can't do this in windows 8.
Richard MacCutchan 3-May-14 10:47am    
Then you cannot write into that directory.

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