1

I am trying to get the installation path of ms word through my code so that I can put its icon in my excel sheet generated through my c# code.

Tried this but no luck.

Here I am trying to get the icon using the whole word installation oath which I know in my device but I want to generalize it.

worksheet.Shapes.AddOLEObject(Filename: @"C:\Users\BJS\Desktop\POC\wordFile.docx", Height: 80, Width: 90, DisplayAsIcon: true, IconFileName: @"C:\Program Files (x86)\Microsoft Office\Office12\WINWORD.EXE", IconIndex: 2, IconLabel: "WordFile", Top: _rng.Top, Left: _rng.Left);

Generalize the path which will work for all users

HasithaJay
  • 355
  • 2
  • 9
b_J
  • 115
  • 10
  • Is your code running on the user machine? Because otherwise there isn't any reliable way to guess the path – Slai May 27 '19 at 11:04
  • Maybe it would be easier to embed that icon into your project and use as ressource? – nilsK May 27 '19 at 11:07

1 Answers1

0

I think you can archieve that with the registryeditor. Open the key HKEY_Classes_Root\Word.Application\CLSID and save the Key Value. Search it in HKEY_Classes_Root\WOW6432Node\CLSID\{your_value}\Localserver32 (that's works for x64 systems, for x32 if i remmember right the path is "System" and not "WOW6432Node").

For how to read a registrykey in c# you can follow that SO link

As @Slai Say, that Will work only if you are Talking of server word Path and not browser user path

Legion
  • 760
  • 6
  • 23