找到VSTO Outlook Addin的安装目录和工作目录;或任何 Office 插件 [英] Find Install directory and working directory of VSTO Outlook Addin; or any Office Addin

查看:65
本文介绍了找到VSTO Outlook Addin的安装目录和工作目录;或任何 Office 插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 VSTO Outlook 插件,它使用一个库 Html2Xhtml.dll (.NET),它通过执行 System.Diagnostic.Process.Start() 调用另一个 Html2xhtml.exe.

I created a VSTO Outlook Addin that uses a library Html2Xhtml.dll (.NET) which calls another Html2xhtml.exe by executing System.Diagnostic.Process.Start().

但是,它无法调用 Html2xhtml.exe(我认为),因为即使从 Visual Studio 启动,工作目录也是当前用户的我的文档"文件夹.我无法控制 Html2Xhtml.dll 中的代码,所以我不能使用绝对路径;但我想我可以在运行时更改加载项的工作目录.

However, it fails to call Html2xhtml.exe (i think) because the working directory even when launched from Visual Studio is the current user My Documents folder. I have no control over the code in Html2Xhtml.dll so I cannot use absolute path; but I suppose I can change the working directory of the Add-in at runtime.

但是,如果我通过 ClickOnce 或其他一些我不知道用户将选择的安装路径的方式安装它,我怎么能找到我的 Html2xhtml.exe?

However, If I install this via ClickOnce or some other means where I do not know the install path the user is going to choose, how am I suppose to find my Html2xhtml.exe?

推荐答案

我找到了答案 此处,全部归功于 robindotnet.wordpress.com.

I found the answer here, full credits to robindotnet.wordpress.com.

//Get the assembly information
System.Reflection.Assembly assemblyInfo = System.Reflection.Assembly.GetExecutingAssembly();

//Location is where the assembly is run from 
string assemblyLocation = assemblyInfo.Location;

//CodeBase is the location of the ClickOnce deployment files
Uri uriCodeBase = new Uri(assemblyInfo.CodeBase);
string ClickOnceLocation = Path.GetDirectoryName(uriCodeBase.LocalPath.ToString());

这篇关于找到VSTO Outlook Addin的安装目录和工作目录;或任何 Office 插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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