我正在构建一个简单的VS2008加载项。存储自定义运行时设置的最佳做法是什么?您在哪里存储app.config以及如何从加载项访问它?
答案 0 :(得分:2)
使用System.IO.IsolatedStorageFile尝试这样的事情(尚未测试示例代码......只是为了表明这个想法)
<强>编写强>
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();
}
}
}