views:

814

answers:

1

I'm building a simple VS2008 add-in. What is the best practice for storing custom run-time settings? Where do you store the app.config and how do you access it from the add-in?

+2  A: 

Try something like this with System.IO.IsolatedStorageFile (haven't tested sample code.. it's just to show the idea)

Writing

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();
          }             
       }
     }
JB Brown