Alon M
Alon M

Reputation: 1683

Writing To Existing XML FILE

I have a xml file, that looks something like this:

<?xml version="1.0" encoding="utf-8"?>
<Settings>
  <WhereDoCopy Path="C:\Users\USER\Desktop\jobs" />
</Settings>

What can I do, to add an Element to that file?

Upvotes: 1

Views: 714

Answers (1)

Nastya Kholodova
Nastya Kholodova

Reputation: 1321

XDocument doc = XDocument.Load("your.xml");
XElement item = new XElement(WhereDoCopy ,
                new XAttribute("Path", "C:\Users\USER\Desktop\jobs2"));
doc.Root.Add(item);

http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.aspx

Upvotes: 6

Related Questions