I want to save a Xdocument to an xml file , and it seems that silverlight doesn’t accept string type for xdoc.save(string str), so I had to put a stream inside of it , the problem is that when I put a filestream I got an error saying that “Attempt to access the method failed” and that a MethodeAccessException was unhandled here is my code :
XDocument MainLBItems = XDocument.Load("SampleData/MainLBItems.xml");
MainLBItems.Root.Add(new XElement("Item",
new XElement("Title", this.tb_Title.Text),
new XElement("Dscrp", this.tb_Dscrp.Text),
new XElement("Count", "0")));
FileStream fs = new FileStream("SampleData/MainLBItems.xml", FileMode.Open, FileAccess.Write);
MainLBItems.Save(fs);
I’ve only used Silverlight in Windows Phone 7, but I suspect the same applies for desktop Silverlight… you can’t use files directly as you do from the full desktop .NET framework. Instead, you have to use isolated storage. For example:
(Adjust other code using streams too.)