Dear All,
I want to read from and write to an xml file in wp7.How can i do that?
Thanks in advance.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Jul 19, 2011, 10:45 PM EDT
Try this,
Person is an Entity.
GeneratePersonData() is a method which returns collection of persons data.
For writing---
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
xmlWriterSettings.Indent = true;
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("People.xml", FileMode.Create))
{
XmlSerializer serializer = new XmlSerializer(typeof(List
using (XmlWriter xmlWriter = XmlWriter.Create(stream, xmlWriterSettings))
{
serializer.Serialize(xmlWriter, GeneratePersonData());
}
}
}
For reading------
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using(IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("People.xml", FileMode.Open))
{
XmlSerializer serializer = new XmlSerializer(typeof(List
List
this.listBox.ItemsSource = data;
}
}
mahesh112 reputationPosted Jul 19, 2011, 11:20 PM EDT
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Jul 20, 2011, 5:12 AM EDT
mahesh112 reputationPosted Jul 20, 2011, 8:10 PM EDT
Thanks in advance
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Jul 20, 2011, 9:17 PM EDT
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if(myIsolatedStorage.FileExists("People.xml"))
{
using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("People.xml", FileMode.Append))
{
XmlSerializer serializer = new XmlSerializer(typeof(List));
using (XmlWriter xmlWriter = XmlWriter.Create(stream, xmlWriterSettings))
{
serializer.Serialize(xmlWriter, GeneratePersonData());
}
}
}
}in this, the FileMode.Append will open the file if exists for appending or will create a new one.