Ver listado de código
using System;
using System.Net;
using System.IO.IsolatedStorage;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
namespace F.Phone.IO
{
public class PageParameters
{
/// <summary>
///
/// </summary>
/// <param name="targetPage"></param>
/// <param name="parameters"></param>
public static void SetParameters(string targetPage, Dictionary <string, string> parameters)
{
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
XDocument _doc = new XDocument();
XElement _parameters = new XElement("parameters");
foreach (KeyValuePair<string, string> p in parameters)
{
XAttribute parameter = new XAttribute(p.Key, p.Value);
_parameters.Add(parameter);
}
_doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), _parameters);
IsolatedStorageFileStream filepath = new IsolatedStorageFileStream( targetPage + ".parameters", System.IO.FileMode.Create, storage);
System.IO.StreamWriter file = new System.IO.StreamWriter(filepath);
_doc.Save(file);
file.Dispose();
filepath.Dispose();
}
}
/// <summary>
///
/// </summary>
/// <param name="targetPage"></param>
/// <returns></returns>
public static Dictionary <string, string> GetParameters(string targetPage) {
Dictionary <string, string> result=new Dictionary <string, string> ();
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
XElement _xml;
IsolatedStorageFileStream filepath = new IsolatedStorageFileStream(targetPage +".parameters", System.IO.FileMode.Open, storage);
System.IO.StreamReader file = new System.IO.StreamReader(filepath);
_xml = XElement.Parse(file.ReadToEnd());
if (_xml.Name.LocalName != null)
{
foreach (XAttribute att in _xml.Attributes()) {
if (!result.ContainsKey (att.Name.ToString () )){
result.Add(att.Name.ToString(),att.Value);
}
}
}
file.Dispose();
filepath.Dispose();
}
return result;
}
}
}