How do I use app.config with a Visual Studio add-in?
1 answer
Try something like this with System.IO.IsolatedStorageFile (haven't tested sample code .. this is just to show the idea)
Recording
using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForAssembly())
{
using (StreamWriter stream = new StreamWriter(new IsolatedStorageFileStream("YourConfig.xml", FileMode.Create, file)))
{
stream.Write(YourXmlDocOfConfiguration);
}
stream.Flush();
stream.Close();
}
Reading
string yourConfigXmlString;
using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForAssembly())
{
string[] files = file.GetFileNames("YourConfig.Xml");
if (files.Length > 0 && files[0] == "YourConfig.xml"))
{
using (StreamReader stream = new StreamReader(new IsolatedStorageFileStream("YourConfig.xml", FileMode.Open, file)))
{
yourConfigXmlString = stream.ReadToEnd();
}
}
}
+2
source to share