如何在Visual Studio加载项中使用app.config? [英] How to use app.config with Visual Studio add-in?

查看:296
本文介绍了如何在Visual Studio加载项中使用app.config?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个简单的VS2008加载项。存储自定义运行时设置的最佳实践是什么?

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?

推荐答案

尝试使用类似的方法在哪里存储app.config以及如何从外接程序访问它。 System.IO.IsolatedStorageFile (已经t经过测试的示例代码..只是为了说明这个想法)

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

写作

using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForAssembly())
    {
       using (StreamWriter stream = new StreamWriter(new IsolatedStorageFileStream("YourConfig.xml", FileMode.Create, file)))
       {
          stream.Write(YourXmlDocOfConfiguration);
       }
       stream.Flush();
       stream.Close();
     }

阅读

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

这篇关于如何在Visual Studio加载项中使用app.config?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆