我正在开发 Windows 8 xaml C# 应用程序,我正在尝试读取一首歌曲 xml 并将新节点附加到它。代码是:
StorageFolder sf;
sf = KnownFolders.MusicLibrary;
StorageFile file = await sf.GetFileAsync(strSongName);
var item = await file.OpenAsync(FileAccessMode.Read);
IRandomAccessStream raStream;
IOutputStream outputStream;
DataWriter writer;
var lc = ApplicationData.Current.LocalFolder;
var infolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(infolder.Path);
StorageFile file1 = await folder.GetFileAsync("songxml.xml");
var filetest = await file1.OpenAsync(FileAccessMode.Read);
Stream inStream = filetest.AsStreamForRead();
XDocument xdoc = XDocument.Load(inStream);
string content = xdoc.ToString();
raStream = await file1.OpenAsync(FileAccessMode.ReadWriteUnsafe);
outputStream = raStream.GetOutputStreamAt(0);
writer = new DataWriter(outputStream);
StringBuilder outputText = new StringBuilder();
outputText.Append(content.ToString());
运行此代码时出现 System.Unauthorizedaccessexception