gnux8
Posts: 11
Joined: Fri Aug 14, 2015 9:10 am

Uwa c# - Read and Modify Xml File with Linq

Fri Jan 20, 2017 8:40 am

Good Morning everybody,
I've put Xml file into the "Application Data Folder". Im able to read it without any problem.

Code for read the file:

Code: Select all

public string path = @"C:\Users\NewPC\AppData\Local\Packages\45307261-1dc6-4817-b962-2a59d79ec272_h909besz0ssn6\LocalState\Contabilita.xml";

// Load Xml File
XDocument doc = XDocument.Load(path);

IEnumerable<XElement> childList =
  from el in doc.Descendants("Contabilita")
  select el;

 foreach (XElement en in childList)
    {
      foreach (XElement test in en.Elements())
          {
            System.Diagnostics.Debug.Write(test.Name + ": ");
            System.Diagnostics.Debug.WriteLine(test.Value);
              if (test.Name == "Antimanomission")
                 {
                   // Write 8 to the Element Antimanomission
                   test.Value = "8";
                   System.Diagnostics.Debug.WriteLine("passed from here");
                  }
            }
     }
After that I shall save the file with

Code: Select all

doc.Save(path);
path is the source that is pointing to my file. But if i try to pass the "path" I receive this message

cannot convert from 'string' to 'System.IO.Stream'

So far as i can understand need a stream ... but also passing a stream my file is not modified ... is there someone that have a working example ?

sorry but are 3 days that im working on that ...

Thanks you very much

Return to “Windows 10 for IoT”