Click here to Skip to main content
15,173,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
background:- I already developed office automation in my web site. where i done lot of settings like, IMPERSONATION, COM security, IIS and it is working as per required. but all these done for MICROSOFT OFFICE 2003. as far as good. no issue.

Problem:- by now i required to setup my application with MS Office 2010 and 2007 on two different servers. I started with 2007 and when i installed office 2007 and interop for 2007 on my development machine it is not working so i created a dummy application and it is working if i am not using IIS but when i configured this dummy application in IIS than it stops to work.
Key problem is wordDocument is null. so code is not able to open the document. Path impersonation is Okay.
Code:-

C#
object file = @"c:\test\01\test.doc";
ApplicationClass wordApp = new ApplicationClass();
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
Document wordDocument = wordApp.Documents.Open(ref file, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);


I am not able to understand why it is null.
Posted
Updated 3-Sep-11 0:04am
v3
Comments
Prerak Patel 2-Sep-11 7:36am
   
Use code block for code segments.
Philippe Mori 2-Sep-11 7:53am
   
Generally it is not recommanded to uses Office Automation on server. That technology is known to be relatively slow and was not designed for that purpose.

If you are an advanced programmer, you can look at the OpenXML SDK... but it is very low level and thus really not recommanded for beginners. Otherwise, there are plenty of third party solutions availables...
Philippe Mori 3-Sep-11 8:10am
   
Normally user application like Office do not run on servers.. Are you sure that Office is installed for the user that access it from your ASP.NET application.

As mentionned before, Office automation is not really intended to be used on servers. If you search the web, you will see that many people recommand not to uses Office automation to generate documents on a server. It won't scale well.

1 solution

I don't know the exact reason, but I have faced the same issue with Office 2010.
The work around is to put some delay between application creation and document open.
I hope this helps.
   
Comments
mahesh__kumar__sharma 2-Sep-11 7:49am
   
I added System.Threading.Thread.Sleep(1000 * 5); before creating
System.Threading.Thread.Sleep(1000 * 5);
Document wordDocument = wordApp.Documents.Application.Documents.Open(ref file, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);

But no Luck. :(
Prerak Patel 2-Sep-11 7:58am
   
Then let's just wait for some different answer. I was lucky that it worked for me.
I would still like you to do one more thing. Put a delay after document open and try to open it again. I read it somewhere while searching for that problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900