ConfigurationManager.OpenExeConfiguration的VSTO Word加载项问题 [英] VSTO Word Add-in problem with ConfigurationManager.OpenExeConfiguration

查看:72
本文介绍了ConfigurationManager.OpenExeConfiguration的VSTO Word加载项问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用VS 2010(.Net 4.0 / VSTO4)创建了一个Word加载项。对于安装程序,我正在创建一个MSI。我想在MyAddin.dll.config中做一些读/写操作,所以我是 使用

I have created a Word Add-in using VS 2010 (.Net 4.0/VSTO4). For installer, I am creating an MSI. I wanted to do some read/write operation in MyAddin.dll.config so I am  using

ConfigurationManager.OpenExeConfiguration

如果我在"程序文件"中安装加载项,如果我检查config对象的"FilePath"属性,它是"C:\Program Files \ Microsoft Office \ Office12 \ Winname.exe.config"而如果我在其他文件夹中安装相同的MSI(而不是在Program Files中),则相同的属性
将返回<< MyAddin InstallPath> \ MyAddin.dll.config"。

If I install the Add-in in "Program Files", if I check the config object's "FilePath" property, it's "C:\Program Files\Microsoft Office\Office12\Winword.exe.config" whereas if I install the same MSI in some other folder (not in Program Files), the same property returns "<MyAddin InstallPath>\MyAddin.dll.config".

我测试的环境:Win 7,32位,Office 2007

Environment where I test this: Win 7, 32 bit, Office 2007

仅仅是为了获取更多信息,我在PerfMon中观察到使用".Net CLR Loading>当前的appdomains"计算器,当它加载MyAddin时,它会创建appdomain,当我卸载它时,它会删除appdomain以确保创建了MyAddin的AppDomain。

Just for additional info, I have observed in PerfMon using ".Net CLR Loading > Current appdomains" counter that when MyAddin is loaded, it creates appdomain and when I unload it, it removes appdomain to ensure that AppDomain for MyAddin is created.

如果你能给出一些指针,那将会很有帮助对于此问题与"程序文件"中的安装为什么它的表现如此以及我如何解决它。

It would be great help if you can give some pointer for this issue with the installation in "Program Files" on why it's behaving like this and how I can resolve it.

提前致谢,

推荐答案

  嗨印度人,

 

感谢您在MSDN论坛上发帖。

 

 

 

< span style ="font-family:" Times New Roman"," serif" ;; font-size:12pt"> Accord根据你的描述,你想访问应用程序执行配置文件是不是?

 

 

 

如果是,请尝试这个片段:

 

 


   RegistryKey currentKey = Registry.CurrentUser.OpenSubKey("Software");
   currentKey = currentKey.OpenSubKey("Microsoft");
   currentKey = currentKey.OpenSubKey("Office");
   currentKey = currentKey.OpenSubKey([Office Application Name]);
   currentKey = currentKey.OpenSubKey("AddIns");
   currentKey = currentKey.OpenSubKey([Add-in Name]);
   string exePath = (string)currentKey.GetValue("Manifest");
   exePath = exePath.Replace("file:///","");
   exePath = exePath.Replace("/", @"\");
   try
   {
    Configuration conf = ConfigurationManager.OpenExeConfiguration(exePath);
    MessageBox.Show(conf.FilePath);
   }
   catch (Exception ex)
   {
    MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
   }


这篇关于ConfigurationManager.OpenExeConfiguration的VSTO Word加载项问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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