For write access you will need to use IsolatedStorage. You can check if the file exists and load it from IsolatedStorage otherwise load it from a resource. For read-only access you can just load it from a resource. Add the xml files to your project check Build Action is Content.
XDocument doc = LoadFromIsolatedStorage(name);
if (doc == null)
{
doc = LoadFromResource(name);
}
////////////////////////////
public static XDocument LoadFromResource(string name)
{
var streamInfo = Application.GetResourceStream(new Uri(name, UriKind.Relative));
using(var s = streamInfo.Stream)
return XDocument.Load(s);
}
public static XDocument LoadFromIsolatedStorage(string name)
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
if (store.FileExists(name))
{
using(var stream = store.OpenFile(name,FileMode.Open))
return XDocument.Load(stream);
}
else
return null;
}
}
public static void SaveToIsolatedStorage(XDocument doc, string name)
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
var dir = System.IO.Path.GetDirectoryName(name);
if (!store.DirectoryExists(dir))
store.CreateDirectory(dir);
using (var file = store.OpenFile(name, FileMode.OpenOrCreate))
doc.Save(file);
}
}