0

I have created a .msi installer file for my PowerPoint add-in developed using C# VSTO. I have to open a help file pdf on ribbon button click. I have embedded the help file pdf with the msi package.

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?

Any help/suggestion is appreciated. Thanks.

gkb
  • 1,449
  • 2
  • 15
  • 30

2 Answers2

0

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 );
Mitja Bezenšek
  • 2,503
  • 1
  • 14
  • 17
  • Thanks Mitja, but the code shared by you gives the ClickOnce Deployment Folder path (C:\Users\username\AppData\Local\Apps\2.0) while what I want is the ApplicationFolder(where all the application files like .vsto and dlls are saved) path that we mention in the file system while building the .msi package. Sorry if I was not clear during asking the question. – gkb May 08 '14 at 13:42
  • Hm strange, I guess that is due to the ClickOnce deployment. We use Wix installer and it points to the right folder. Here is a similar question, that might help: http://stackoverflow.com/questions/9886957/find-install-directory-and-working-directory-of-vsto-outlook-addin-or-any-offic – Mitja Bezenšek May 08 '14 at 17:19
0

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. Assuming that the property name for that location is INSTALLDIR, you'd create a registry key something like this:

RegistryKey Id="MySetupRegKey" Root="HKLM" Key="Software\MyLocation" Action="createAndRemoveOnUninstall"

RegistryValue Id="MySetupRegValue" Type="string" 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.

PhilDW
  • 20,260
  • 1
  • 18
  • 28