Monday, March 26, 2012

please help

hi i am using a word application to get data from a word file, i use the following code to open the word application and document:

Dim objWord As New Word.Application
Dim docNew As New Word.Document

and i am using the following code to close and quit the applications:

'Close the Automation object
objWord.Quit()
' Cleanup the unmanaged objects
System.Runtime.InteropServices.Marshal.ReleaseComObject(objWord)

but when i look at the processes in my task manager winword.exe with username asp.net never ends, and the more i run the application, the more winword.exe's that open. Am i trying to close it wrong?
thanks in advance for any help!I'm not familiar with using word with ASP.NET, but after you release the object you should set it = nothing. This marks the object for garbage collection and allows the object to be destroyed.
You need to do:

docNew.Close(Word.wdSaveOptions.wdDoNotSaveChanges)
Marshal.ReleaseComObject(docNew)
docNew = nothing

objWord.Quit(Word.wdSaveOptions.wdDoNotSaveChanges)
Marshal.ReleaseComObject(objWord)
objWord = nothing

Brian
Thanks a million, that works perfectly! thanks for your help!

0 comments:

Post a Comment