Saving causes Word to hang on the server

A

Akbur

Dear all,

I have developed a method in C# which creates an instance of Word, adda a
document, then populates the Word doc with some text. It then saves it,
closes the doc and quits Word.

Now this is the problem: The method works perfectly on the command line and
through IE on my development machine (Win XP Pro, Office 2003) but it fails
to work on the server (Windows 2000 Advanced Server, Office 2000) when called
through IE (it works fine through the command line even on the server!) I
can see (using ProcessExplorer) that the instance of Word is being created
and is sub-process of svchost.exe and that the actual Word doc is also being
created on the hard disk. However, the Word process still has a lock on the
doc. Through further analysis and logging, I believe it is falling down when
I try to save the document using:

aDoc.SaveAs(ref filetosave, ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref
missing);

The SaveAs method is not passing control back to my method which explains
why the generated Word doc is still locked and it is therefore halting the
overall execution. When we do run the interop code and we kill the hanging
Word process ourselves (using ProcessExplorer) we get the following exception
in EventViewer:

System.Runtime.InteropServices.COMException (0x800706BE): The remote
procedure call failed.

Does any one know of any issues that could be causing this behaviour? I
don't think its an IIS specific issue because when I by-pass IIS and use my
own web server (which is much much simpler) it still causes the same effect
of hanging.

Any advice would be appreciated!

Cheers,
Akbur
 
C

Cindy M.

Hi =?Utf-8?B?QWtidXI=?=,

Possibly, a message box is displayed in the application, waiting for user
intervention. This is one of the main reasons why MSFT doesn't support
automating Office applications server-side, and there's not a lot you can do
about it.

Since you have Office 2003, I recommend you save the base document as XML. Then
use the usual XML tools to edit the XML content or use a transform to populate
the data. No automation involved; no chance the Word app will hang.

Another possibility would be to create a VSTO document then use the
DocumentServer functionality to update the data cache, remove the VSTO
customizations. The result would be a "normal" Word document in the binary file
format.
I have developed a method in C# which creates an instance of Word, adda a
document, then populates the Word doc with some text. It then saves it,
closes the doc and quits Word.

Now this is the problem: The method works perfectly on the command line and
through IE on my development machine (Win XP Pro, Office 2003) but it fails
to work on the server (Windows 2000 Advanced Server, Office 2000) when called
through IE (it works fine through the command line even on the server!) I
can see (using ProcessExplorer) that the instance of Word is being created
and is sub-process of svchost.exe and that the actual Word doc is also being
created on the hard disk. However, the Word process still has a lock on the
doc. Through further analysis and logging, I believe it is falling down when
I try to save the document using:

aDoc.SaveAs(ref filetosave, ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref
missing);

The SaveAs method is not passing control back to my method which explains
why the generated Word doc is still locked and it is therefore halting the
overall execution. When we do run the interop code and we kill the hanging
Word process ourselves (using ProcessExplorer) we get the following exception
in EventViewer:

System.Runtime.InteropServices.COMException (0x800706BE): The remote
procedure call failed.

Does any one know of any issues that could be causing this behaviour? I
don't think its an IIS specific issue because when I by-pass IIS and use my
own web server

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
A

Akbur

Hi,

Cindy - you made a good point and this prompted me to investigate if there
were any message boxes appearing in the Word instance when invoked from code.
During my investigation I found the following Knowledge Base article:
http://support.microsoft.com/kb/288366/ and found that the user being used to
create the instance of Word was not an interactive one and therefore I had to
create an interactive account as per the above article. Problem solved.

Cheers,

Akbur
 
A

Ahmed Sobhy

i use Office 2007 , Sharepoint 2007,Windows Server 2008 and VS2008 my case is
i develop ASP.Net Web Application and i will host it as a web part in
sharepoint i use Microsoft Office Library to generate Word File In run time
every thing was fine when i test the Web Application out side the server but
when i host the webpart to the shrepoint i faced a lot of problems and many
exception.
Can anyone tell me if i missing Something?
Please Help...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top