简体   繁体   English

如何使用C#VSTO在PowerPoint中单击自定义按钮上的msi包来打开帮助文件pdf

[英]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.

相关问题 如何使用C#VSTO在PowerPoint中自动卸载自定义加载项? - how to auto-unload a custom add-in in PowerPoint using C# VSTO? 有没有一种方法可以使用C#VSTO在PowerPoint 2010中将图像与外接程序文件一起嵌入? - Is there a way to embed an image with the add-in file in PowerPoint 2010 using C# VSTO? 通过 VSTO 加载项 (C#) 访问 PowerPoint 文件中的图像 - Accessing Images in PowerPoint file via VSTO Add-In (C#) 使用 C# VSTO 在 Powerpoint 中获取所选图表 - Get the selected chart in Powerpoint using C# VSTO 如何直接打开Outlook文件附件不保存? (带 C# VSTO) - How to Open Outlook file attachment directly not saving it? ( with C# VSTO) 如何在资源文件C#中打开PowerPoint文件 - How to open PowerPoint file in resource file C# 如何使用C#VSTO读取presentationML并将输出放置在PowerPoint的活动幻灯片上 - How to read presentationML and place the output on Active slide of powerpoint using c# VSTO 如何使用VSTO和C#更改PowerPoint图表中的值? - How can I change the values in a PowerPoint chart using VSTO and C#? 在浏览器中单击按钮后未打开ODT文件。 如何使用C#代码打开ODT文件? - ODT files not opened on button click in browser. How to open an ODT file using C# code? 如何打开在C#中已修改的PowerPoint文件 - how to open a powerpoint file that has been modified in c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM