Reputation: 1143
i am using this code to add a node to an XmlDocument and then saving it to an existing file, however i keep getting this error message:
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
The code i am using is this:
string xml = string.Empty;
StorageFolder storageFldr = Package.Current.InstalledLocation;
storageFldr = await storageFldr.GetFolderAsync("Scores");
StorageFile sf = await storageFldr.GetFileAsync("Scores.xml");
xml = await FileIO.ReadTextAsync(sf, Windows.Storage.Streams.UnicodeEncoding.Utf8);
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(xml);
IXmlNode xNode = xDoc.CreateElement("score");
xNode.InnerText = "Hello this is a test";
xDoc.DocumentElement.AppendChild(xNode);
await xDoc.SaveToFileAsync(sf);
I would appreciate any help.
Thank you all in advance.
Upvotes: 1
Views: 1678
Reputation: 365
I faced the same problem, but this worked for me:
Windows.Storage.StorageFolder sf = await ApplicationData.Current.LocalFolder.CreateFolderAsync("EMP", CreationCollisionOption.OpenIfExists);
StorageFile st = await sf.CreateFileAsync("Employee.xml", CreationCollisionOption.OpenIfExists);
await dom.SaveToFileAsync(st);
Upvotes: 2
Reputation: 2852
I don't believe this is possible without your application having elevated privileges (trusted application - with certificate or an OOB app).
You can set your app up as an out of browser application by following this guide.
How to: Configure an Application for Out-of-Browser Support
However this maybe possible by using isolated storage to save - then modify the XML.
see this example XML File with IsolatedStorage
Upvotes: 1