Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XDocument.Save to specific directory?

Tags:

c#

xml

I'm using this XML classes for the first time and can't find this piece of info.

I'm doing:

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

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

like image 297
Nacho Avatar asked Apr 01 '26 06:04

Nacho


2 Answers

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

like image 193
Reed Copsey Avatar answered Apr 03 '26 19:04

Reed Copsey


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

like image 35
Mike Avatar answered Apr 03 '26 20:04

Mike



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!