【发布时间】:2014-01-20 13:04:09
【问题描述】:
我正在使用此代码将节点添加到 XmlDocument,然后将其保存到现有文件中,但是我不断收到此错误消息:
访问被拒绝。 (来自 HRESULT 的异常:0x80070005 (E_ACCESSDENIED))
我使用的代码是这样的:
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);
我将不胜感激。
提前谢谢大家。
【问题讨论】:
-
使用 Windows.Storage.ApplicationData.Current.LocalFolder 存储应用程序数据。关注这个msdn.microsoft.com/en-us/library/windows/apps/hh700361.aspx
标签: c# silverlight xaml windows-8 windows-8.1