Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interop.Word Documents.Open is null

I am trying to open .docx file and convert to PDF using Interop.Word.Application. It works as console application but If I use the same in my web application it doesn't work. I tried to see the permissions on the folder. I gave 'Network Service' with full control, but still I get object reference not set at word.Documents.Open. Could you please let me know what could be the problem? I am stuck with this error. Please let me know. I appreciate any suggestions. Thank you.

    Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();

    object oMissing = System.Reflection.Missing.Value;

    word.Visible = false;
    word.ScreenUpdating = false;
    string fileName = @"c:\OUTPUT\test.docx");
    Document doc = word.Documents.Open(filename, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing, ref oMissing);
        doc.Activate();
like image 464
nav100 Avatar asked May 31 '12 16:05

nav100


4 Answers

If you are still looking for the answer I have found it just a moment ago for my project.

Open DCOM Config Settings:

  1. Start -> dcomcnfg.exe
  2. Computer
  3. Local Computer
  4. Config DCOM
  5. Search for Microsoft Word 97-2003 Documents -> Properties

Tab Identity, change from Launching User to Interactive User

like image 171
Gianni B. Avatar answered Nov 15 '22 09:11

Gianni B.


Try this it may help you.

  • Create a new "Desktop" directory inside of "C:\Windows\SysWOW64\config\systemprofile\"

it works for me after a long long long day searching for the solution.

It seams to be a profile problem.

like image 45
nacx08 Avatar answered Nov 15 '22 10:11

nacx08


I did the following steps and it worked all right:

  • Create the desktop folder
  • Change the DCOM element to login with a specific user instead of an launching/interactive user
  • Changed the service so it started as the same specific user

Edit on 2019-09-29. Due to a big windows update I had to do the exact progress all over again.

like image 6
Kevin Cloet Avatar answered Nov 15 '22 10:11

Kevin Cloet


This worked for me. https://social.msdn.microsoft.com/Forums/en-US/0f5448a7-72ed-4f16-8b87-922b71892e07/word-2007-documentsopen-returns-null-in-aspnet.

If this helpe you, please make it answer

like image 1
MJSL Avatar answered Nov 15 '22 10:11

MJSL