How to make IIS7 play nice with Office Interop

How to make IIS7 play nice with Office Interop

I’ve just started working on a new project for which we had to dig out one of our older libraries. We wrote it to retrieve data from MS Excel workbooks using the Office interop assemblies, and thus far it has never given us issues. A slight change this time round was that we were using our library in an ASP.NET site rather than a desktop application. As a result I was faced with two errors that we’d never seen before.

Error Message:

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

Solution:

This is a COM permissions problem.

  1. Start > Run > dcomcnfg (or “mmc -32” and then add the Component Services snap-in manually if you can’t find the app under step 3)
  2. Navigate to Component Services > Computers > My Computer > DCOM Config
  3. Locate the MS application giving you trouble (eg: “Microsoft Excel Application” for Excel or “Microsoft Word 97 – 2003 Document” for Word)
  4. Right click > Properties
  5. On the security tab: Select Customize under Launch and Activation Permissions and click Edit…
  6. Add the account under which the site is running (eg: Network Service) and assign Local Launch & Local Activation permissions
  7. Voila!

Error Message:

[COMException (0x800a03ec): Microsoft Excel cannot access the file ‘<filename>’. There are several possible reasons:
ΓÇó The file name or path does not exist.
ΓÇó The file is being used by another program.
ΓÇó The workbook you are trying to save has the same name as a currently open workbook.

Solution:

This seems to be an issue with Excel/Word/etc not having access to a profile when being started via the interop route.

  1. Open Windows Explorer
  2. Depending on whether you installed a 32bit or 64bit version of office you will need to do one  (or both) of the following:
    1. 32bit Office installation: Navigate to C:\Windows\System32\config\systemprofile
    2. 64bit Office installation: Navigate to C:\Windows\SysWOW64\config\systemprofile
  3. Verify the folder “Desktop” exists (create it if it’s not there)
  4. Right click > Properties
  5. On the security tab: Add the account under which the site is running (eg: Network Service) with default permissions (Read & execute; List folder contents; Read)
  6. Voila!

Many thanks to the contributors of this discussion.

Leave a Reply

Your email address will not be published.