Search code examples
c#asp.net

Microsoft.Office.Interop.Word - Word experienced an error trying to open the file


We have an ASP.Net Web application (C#) which is opening a Word file via Microsoft.Office.Interop.Word.

Firstly I realise this is not the recommended approach and a library such as TextControl or Asppose should be considered and we'll be looking at replacing the use of Microsoft.Office.Interop.Word with one such library.

However, in the short term, I would like to get it working and the code we have is working on my development machine, the client's Test server but not their UAT server.

The client's Test server and UAT server are seemingly identical, and I've tried looking at various DCOM Config settings without joy.

I've looked at other Stack Overflow questions on Microsoft.Office.Interop.Word but none of the suggestions have helped.

To help test the issue I put together a simple test application which attempts to open a Word document using the below code

var wordApplication = new Application();            
var wordDocument = wordApplication.Documents.Open(txtPath.Text);
wordApplication.Visible = true;

When run a Word process appears in Task Manager however the below error appears. I've obviously checked file permissions etc. Any suggestions welcome.

enter image description here


Solution

  • In the end, my issue was resolved after following the steps outlined on https://stackoverflow.com/a/16481091/1302730.

    • I have created a new user (in user group), called WordUser
    • I have created in IIS new application pool with WordUser permission; Load User Profile must be true
    • DCOM I have set to use WordUser, on Security tab I've added WordUser with Launch and activation Permission and Access Permission

    It transpires that it seems the creation of the local user kick-started something as even if I switch the application to use the previous application pool and the DCOM setting to use the previously stipulated user my application works.