简体   繁体   中英

Add datas from WP8 to a XML file

I am trying to add the datas obtained from my list picker into an xml. I could not figure out where the mistake is since I am new to this.

C# code

 using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
        {
           var isoFileStream = new IsolatedStorageFileStream(@"D:\Backup\task\Project\
     Project\FinalDatas.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite, store); // I get an exception here
            var xDoc = XDocument.Load(isoFileStream);
            isoFileStream.Close();


          var contactsElement =  
                              new XElement("Noofppl",
                             new XElement("ppl",
                        new XElement("Adults", ListAdults.SelectedItem.ToString()),
                        new XElement("children", ListChildren.SelectedItem.ToString())));


            //    IsolatedStorageFileStream location = new IsolatedStorageFileStream(ListAdults.SelectedItem.ToString() + ".item", System.IO.FileMode.Create, storage);
       xDoc.Root.Add(contactsElement);
    xDoc.Save(isoFileStream);
    isoFileStream.Close();
        }

I have my xml file on the same project and the code likes

     <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
     <Noofppl>
      <ppl>
       <Adults>

       </Adults>
        <children>

        </children>
        </ppl>
        </Noofppl>

Try just adding the XDocument without the IsolatedStorageFileStream :

XDocument xDoc = XDocument.Load(@"D:\Backup\task\Project\
 Project\FinalDatas.xml);

If possible have a look at this & the sample .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM