I am new to WP7.
I followed this tutorial to read and write a xml file but when i read the xml file it only shows me the top row of xml file.I don’t know how to check weather the xml file is written properly by the program.So.
1.Where to check the xml files that are saved in isolated storage.
2.How to get out of this problem.
My code to Write Xml File In Isolated Storage:
using (IsolatedStorageFile myIsolatedStorage =
IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("mz1.xml", FileMode.Create, myIsolatedStorage))
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
using (XmlWriter writer = XmlWriter.Create(isoStream, settings))
{
writer.WriteStartDocument();
writer.WriteStartElement("person");
writer.WriteElementString("node1", "value1");
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
}
}
}
Code to Read Xml File From Isolated Storage:
using (IsolatedStorageFile myIsolatedStorage =
IsolatedStorageFile.GetUserStoreForApplication())
{
IsolatedStorageFileStream isoFileStream =
myIsolatedStorage.OpenFile("mz1.xml", FileMode.Open);
using (StreamReader reader = new StreamReader(isoFileStream))
{
textBlock1.Text= reader.ReadToEnd();
}
}
Output:
<?xml version="1.0" encoding="utf-8"?>
In response to your first question, you can download and install the WP7 Isolated Storage Explorer from codeplex here:
http://wp7explorer.codeplex.com/
Its really easy to use. Just add a couple lines of code to your app.xaml.cs and you’re all set.
In regard to your second question, The code that you have there looks OK. I recently wrote a little WP7 app that did just this kind of thing as well. Here is some of that code:
its up to you, but you may want to consider using LinqToXml. It makes things a bit cleaner IMHO.
I actually have a blog post that does all of this posted here:
http://www.ritzcovan.com/2012/02/building-a-simple-windows-phone-apppart-2/
and you can download all the code as well.
I hope you find it helpful.