How do I use app.config with a Visual Studio add-in?

I am creating a simple VS2008 addon. What's the best practice for storing custom runtime settings? Where do you store app.config and how can I access it from the add-on?

+1


source to share


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







All Articles