Word doc in C# Winform IE control doesn't close.

G

Guest

I need to display and allow the user to print a Word document from within a
C# WinForm application. I'm using the ActiveX Browser control. The Word
document displays correctly, but remains "locked" after the form and
application is closed. If I try to delete the document, the message "File in
use by Microsoft Word" is displayed. How do I correctly close and/or unload
the document?

Also, any example of displaying the printer icon and menu option from within
the Browser control would be appreciated.

Thanks.
 
P

Peter Huang [MSFT]

Hi

From your description, I think the winword.exe process is not quit due to
the unreleased com reference.
Here is a KB about how to do quit Office Application.
317109 Office application does not quit after automation from Visual Studio
http://support.microsoft.com/?id=317109

Also I think we have to use the ExecWB command to recreate our own menu to
do the WebBrowser menu job.
Here is the sample for your reference.

Using the WebBrowser control in .NET
http://www.codeproject.com/csharp/webbrowser.asp


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Thank you.
Are there any examples of this functionality through the Internet Browser
control? I am not directly automating Word. I've placed a browser control on
a Windows Form and am navigating to the Word document.
 
P

Peter Huang [MSFT]

Hi

This depends on how did you use the Word Object modal.
Our end goal is to make sure all the COM Reference will be released
correctly, so that after the Application exited, the Winword will exit too
because all its instance have no reference again.

e.g. the code snippet below will release the wdDoc.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim wdDoc As Microsoft.Office.Interop.Word.Document =
Me.AxWebBrowser1.Document
wdDoc.PrintOut()
System.Runtime.InteropServices.Marshal.ReleaseComObject(wdDoc)
wdDoc = Nothing
End Sub

Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.AxWebBrowser1.Navigate("http://localhost/test.doc")
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Thanks.
I added a call to the form's Dispose method in the Closing event handler and
the problem was resolved. Your suggestion by itself did not resolve the
issue. Maybe because the Browser control is hosted in an MDI child?
Thanks again.
 
P

Peter Huang [MSFT]

Hi

I am glad that you have resolved your problem!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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