-1

In my recent project, I can open and process any office files using the Interop in C#, as long as I know their file types (e.g., ".doc", ".xlsm"".ppt", etc.), and a specific application (e.g., Word or Excel) will be chosen to open the file.

My question is that, is there a unique way to open an office file and process it using Interop in C#? Thanks.

Edited: For instance, given a ".doc" file, I will use Microsoft.Office.Interop.Word to open it. Is there a way in C# to know which application (i.e, Microsoft.Office.Interop.Word, Microsoft.Office.Interop.Excel, Microsoft.Office.Interop.PowerPoint) is associated to open a given file type use interop (I need to use interop to do some processing)?

One way to do it is to store a table with associated application according to difference file types. Is there a better way?

Chang Sun
  • 31
  • 3
  • Could you clarify what you are asking? You can definitely open/process MS Office documents using C# (or any other language) no problem. – dub stylee Feb 27 '15 at 22:33
  • Are you trying to open each file type with its associated app? There's no need for interop, just use `Process.Start(filename)` and it will open the file in the default app. – Thomas Levesque Feb 28 '15 at 00:32

1 Answers1

0

The Office extensibility model doesn't provide anything for that.

Possible solutions are:

  1. Run the file programmatically. It will be open in the default application. Nobody can guarantee that it will be an application from Microsoft Office package.
  2. You can check under registry section HKEY_CLASSES_ROOT for the extension and action details. Documentation for this is on MSDN. Alternatively, you can use the IQueryAssociations interface.

You can read more about that on the Finding the default application for opening a particular file type on Windows forum thread.

Community
  • 1
  • 1
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45