[英]How to open help file pdf from msi package on custom button click in PowerPoint using C# VSTO
I have created a .msi installer file for my PowerPoint add-in developed using C# VSTO. 我已经为使用C#VSTO开发的PowerPoint加载项创建了.msi安装程序文件。 I have to open a help file pdf on ribbon button click.
我必须在功能区按钮单击上打开一个帮助文件pdf。 I have embedded the help file pdf with the msi package.
我已经将帮助文件pdf嵌入了msi软件包中。
I have implemented this feature by using a hard-coded path(the default path where the add-in will get installed) using below code: 我通过使用以下代码使用硬编码路径(将在其中安装外接程序的默认路径)来实现此功能:
private void btnHelp_Click(object sender, RibbonControlEventArgs e)
{
string filepath = @"C:\Program Files (x86)\Microsoft\Office\PowerPoint\AddIns\myAddin\HelpFile.pdf";
string locationToSavePdf = Path.Combine(Path.GetTempPath(), filepath);
Process.Start(locationToSavePdf);
}
But I know that this won't work as soon as the end-user changes the location where she/he wants to install the add-in. 但是我知道,一旦最终用户更改了她/他想要安装外接程序的位置,此操作将不会起作用。 Can any one help me with this so that I can get the path of the help file pdf dynamically(As soon as the user changes the location) or is there any other approach?
任何人都可以帮我这个忙,以便我可以动态获取帮助文件pdf的路径(用户更改位置后),或者还有其他方法吗?
Any help/suggestion is appreciated. 任何帮助/建议表示赞赏。 Thanks.
谢谢。
You can get the location of the currently executing assembly folder with the following commands: 您可以使用以下命令获取当前正在执行的程序集文件夹的位置:
var assemblyInfo = Assembly.GetExecutingAssembly();
var uriCodeBase = new Uri(assemblyInfo.CodeBase);
var helpFileLocation = Path.GetDirectoryName(uriCodeBase.LocalPath) + @"\HelpFile.pdf";
Process.Start(helpFileLocation );
If you are building an MSI file and want to save the final destination folder you can create a registry item to store the value. 如果要构建MSI文件并要保存最终目标文件夹,则可以创建一个注册表项来存储该值。 Assuming that the property name for that location is INSTALLDIR, you'd create a registry key something like this:
假设该位置的属性名称为INSTALLDIR,则将创建一个类似于以下内容的注册表项:
RegistryKey Id="MySetupRegKey" Root="HKLM" Key="Software\\MyLocation" Action="createAndRemoveOnUninstall" RegistryKey Id =“ MySetupRegKey” Root =“ HKLM” Key =“ Software \\ MyLocation” Action =“ createAndRemoveOnUninstall”
RegistryValue Id="MySetupRegValue" Type="string" Name="InstallDir" Value="[INSTALLDIR]" /RegistryKey> RegistryValue Id =“ MySetupRegValue” Type =“字符串” Name =“ InstallDir” Value =“ [INSTALLDIR]” / RegistryKey>
and I've omitted the angle brackets because I haven't figured out how to post them properly :) 并且我省略了尖括号,因为我还没有弄清楚如何正确张贴它们:)
But then you can read that location. 但随后您可以读取该位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.