0

So far manipulating XML (reading/writing) has been a bit more challenging than standard windows. I am trying to open the config file for editing, make changes and then save the file again to disk.

I can open the file as a StorageFile, convert it to XDocument but I am having trouble saving the XDocument to disk, can anyone offer code that would do the trick? Currently I have

             StorageFile file = await installedLocation.GetFileAsync(fileNameAndPath);
            var data = await FileIO.ReadTextAsync(file);
            string actualXML = data.ToString();
            XDocument doc = XDocument.Parse(actualXML);
            // do work
            //save
            MemoryStream ms = new MemoryStream();
            XmlWriter w = XmlWriter.Create(ms);
            doc.WriteTo(w);
Ufuk Hacıoğulları
  • 37,978
  • 12
  • 114
  • 156
mrasmussen
  • 55
  • 1
  • 7
  • take a look at this `MDSN` documentation for Windows App Store http://msdn.microsoft.com/en-gb/library/windows/apps/hh464917.aspx – MethodMan Jan 16 '13 at 16:55
  • thanks, I took a look at that prior, some good info there. – mrasmussen Jan 16 '13 at 17:08
  • Still can't get the save to work. The problem is XDocument.Save takes a stream, does that mean that the changes get written to a stream and then I have to save the stream to disk? – mrasmussen Jan 17 '13 at 15:44
  • look at this stackoverflow link try changing your code to utilize this code here http://stackoverflow.com/questions/10290820/how-write-a-file-using-streamwriter-in-windows-8 – MethodMan Jan 17 '13 at 22:05

1 Answers1

1

If it is throwing Access denied to path, check or try to give permission in your app manifest to respective folders.

i31nGo
  • 1,422
  • 15
  • 11