Share via


Failed to open a Word doc from ASP.NET

Question

Wednesday, May 1, 2013 2:40 AM

Hi,

I have a DLL, which I invoke from an ASP.NET web page, in which there is a line to open an existing Word document:

m_wordDoc = m_wordApp.Documents.Open(strFilePath);

where "m_wordApp" is an "Application".

When I run the website from Visual Studio, that line of code opens the Word doc fine. But after I deploy it to the web server, the it returns NULL without any error.

I have assigned "Everyone" full control on the folder that contains the Word document.

I installed Visual Studio onto the web server. I opened the website through "File System". The Word document is opened fine. But if I open the website through "Local IIS", the line will return NULL.

Please help!

All replies (2)

Thursday, May 2, 2013 1:41 AM âś…Answered

Worked out how to get this working:

*********** 1. Find out your website is running under which identity ************

  1. Open IIS and click your website;

  2. Click "Advanced Settings..." on the right pane. The "Application Pool" dialog
       will show up. Find out the "Application Pool", then close this dialog.

  3. Click "Application Pools" under IIS. Click the application pool you just found
       out, then click "Advanced Settings" on the right pane. The "Application Pool" 
       dialog will show up. Find out the "Identity". This could be something like
       "NetworkService". This is the identity which runs your website. We need to 
       allow it to access the Word DCOM component.
       

  4. Again click your website and double-click the "Authentication" icon in the middle
       pane.
       

  5. Right-click "Anynymouse Authentication" and select "Edit". Make sure the 
       "Application pool identity" radio button is selected.
       
       

*************** 2. Configure the Word DCOM ***************

  1. Windows "Start | Run | dcomcnfg" to start DCOM configuration;

  2. Go to "Component Services | Computers | My Computer | DCOM Config", 
       right-click "Microsoft Word 97 - 2003 Document" and select "Properties";

  3. Go to "Identity" tab page, among the three radio buttons "The interactive user", 
       "The launching user" and "This user", select the last one, and put in the user
       who installed Office onto this server/PC. This is one of the tricks otherwise
       you will get errors once the backend code (such as ASP.NET) tries to invoke 
       the Word DCOM component while this user is not logged in. When you test on
       your development PC using Visual Studio this error will never happen because
       you installed Office and you are always logged in when you test.

  4. Go to the "Secutiry" Tab, on the "Lanuch and Acctivation Permissions" group box,
       Add the identity which runs your website - the one you found out earlier - something
       like "NETWORK SERVCIE", and allow local launch and activation. Some link also
       mentioned adding "IUSR_<machinename>". 


Thursday, May 2, 2013 2:53 AM

Hi,

I'm glad to hear that your issue has been resolved.

Thank you for sharing your solution which might be very helpful to other community members.

Have a nice day.

Quist Zhang [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.