473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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.
Dec 5 '05 #1
5 3816
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.

Dec 6 '05 #2
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.

""Peter Huang" [MSFT]" wrote:
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.

Dec 6 '05 #3
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.ReleaseComO bject(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.

Dec 7 '05 #4
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.
""Peter Huang" [MSFT]" wrote:
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.ReleaseComO bject(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.

Dec 7 '05 #5
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.

Dec 8 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Carolina | last post by:
Hi. I have a MDIchild form called Form1. In Form1_Load code, the form populates a Listview control based on a datareader, but I want to close the form inmediately and return to the parent form,...
10
by: Brian Brown | last post by:
I have code which works as an asp.net page that posts an xml file to web page and gets a response back. When the the calls GetResponse() it goes into the page it's posting to to and works fine....
9
by: Dayne | last post by:
I need to have a auto timeout feature for a webform application(vb.net). Basically, I want to close the application if the user does not have a keyboard or mouse input after a specific period of...
0
by: Cenray | last post by:
How to generate a web request from a Winform Application using a WebService? In a C# Windows Application, when I try to genrate a web request using the following code, it is woking fine ...
3
by: Emily John | last post by:
I have a word document that I need to send it as an attachment to an XML file. Basically, converting into byte array or using some encoding mechanism. This has to be done through XML serialization...
0
by: Marco | last post by:
Hello, I have a WinForm control embedded in IE that crashes everytime I close my browser. If i click on a link in IE when the control is loaded and brings me to another page, IE also crashes. ...
8
by: Sunil Menon | last post by:
Dear All, We are developing applications in ASP.Net...in one of our applications we would like to use a GridControl...we have tried to use a Server-Side Grid control but found the speed to be an...
0
by: dadizhu | last post by:
Hi, everyone. I ran into an UI freeze issue with threading and simplied the problem down to the following sample code. The logic is as follows: 1. The main UI thread creates a non-UI STA...
8
by: Bllich | last post by:
hello, I have winForm app and I have some text and pictures that I want to save into a word file when I read it from a database. I don't know how many text or pictures do I have for one value in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.