Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stopping a Word process cleanly

Status
Not open for further replies.

GBall

Programmer
Joined
May 23, 2001
Messages
193
Location
GB
Hi,
I have an application which creates a quote in a word document and displays it to the screen.
The user has the option to go back to the application and enter another quote while Word is still open.
This resulted in an error that c# could not create the quote document as it was already open fair enough.
I used to kill the process, but it left temporary Word documents lying around and when you logged off, Word would ask you if you wanted to save each one or recover each one.
I solved this by finding the process and closing the open window before they generate a quote, as follows.

foreach ( Process p in processes )
{
if ( p.MainWindowTitle.IndexOf( "quote.doc" ) != -1 )
{
p.CloseMainWindow();
}
}

This works fine, until they print the document.
Then, when you close the document, you get a prompt asking if you want to save your changes, even though all that has happened is that the document has been printed!

Anyone with a suggestion to get around this ?

(I've thought of serialisng the documents, but this is going on laptops to salesmen and disk housekeeping would be a nightmare)

TIA


Regards,
Graham
 
Don't know why it would ask you again to save the changes just after saving and printing. But just a throught why don't you save the document again after the print so that the user won't get that message?

-Kris
 
Call System.Runtime.InteropServices.Marshal.ReleaseComObject(wordObj) to release the object.
-obislavu-
 
Thanks for your replies.
Kris11 - They print the document from Word, so I do not know if it has been printed or not.
obislavu - that sounds like a good idea, but the reason I've gone to look for the process, is that the application has left the procedure that created the word document and gone back to handling screen input, so I believe I've lost the object scope and thus the ability to marshal it. Or is that not the case ?

Regards,
Graham
 
Just figured it out !
I've moved the creation of the word document to application level, so I retain control of it - works ok, but I now have a different problem.
Before, when I create a word document in C#, it always appeared on top of the form that created it.
Now it always appears behind it.
Is there a way that I can ensure that it is displayed on top ?
thanks.

Regards,
Graham
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top