XDocument.Save to a specific directory?

I am using these XML classes for the first time and cannot find this information.

I am doing:

xmlDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
xmlDoc.Add(new XElement("Images"));
xmlDoc .Save("C:\\Backup\\images.xml");

      

But it doesn't work. It only works if I only use the filename like "images.xml", but of course the file is saved in the execution path.

+2


a source to share


2 answers


By default, you most likely won't be able to save "C: \ Backup" unless you run your program under elevated privileges. By default, you can only save "custom" folders.



+6


a source


Worked for me, there must be a permissions issue. Try another directory or make sure c: \ Backup exists



+2


a source







All Articles