0

As the headline states, when i try to use doc.Save("data.xml"); it gives me the error "Argument 1: cannot convert from 'string' to 'System.IO.Stream'

I've tried both of these:

public void holder()
    {
        string location = "Employees.xml";
        XDocument doc = XDocument.Load(location);
        XElement person = doc.Element("Person");
        person.Add(new XElement("Employee",
                   new XElement("Name", "David"),
                   new XElement("Dept", "Chef")));
        doc.Save(location);
    }


 public void holder()
    {

        XDocument doc = XDocument.Load("Employees.xml");
        XElement person = doc.Element("Person");
        person.Add(new XElement("Employee",
                   new XElement("Name", "David"),
                   new XElement("Dept", "Chef")));
        doc.Save("Employees.xml");
    }

The loading part gives me no problems, its the saving..

Hudlommen
  • 89
  • 1
  • 11

1 Answers1

0

For UWA you need to use the overload that accepts a stream, once you get a stream for the file you want to open just pass it in.

public void holder(Stream input, Stream output) {

    XDocument doc = XDocument.Load(input);
    XElement person = doc.Element("Person");
    person.Add(new XElement("Employee",
               new XElement("Name", "David"),
               new XElement("Dept", "Chef")));
    doc.Save(output);
}

To see how to get the input and output streams on a UWA program see this question

Community
  • 1
  • 1
Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431