473,657 Members | 2,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3825
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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim wdDoc As Microsoft.Offic e.Interop.Word. Document =
Me.AxWebBrowser 1.Document
wdDoc.PrintOut( )
System.Runtime. InteropServices .Marshal.Releas eComObject(wdDo c)
wdDoc = Nothing
End Sub

Private Sub Form3_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Me.AxWebBrowser 1.Navigate("htt p://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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim wdDoc As Microsoft.Offic e.Interop.Word. Document =
Me.AxWebBrowser 1.Document
wdDoc.PrintOut( )
System.Runtime. InteropServices .Marshal.Releas eComObject(wdDo c)
wdDoc = Nothing
End Sub

Private Sub Form3_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Me.AxWebBrowser 1.Navigate("htt p://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
2769
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, if there was a problem connecting to the database and populating the Listview control. I've tried something like this:
10
472
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. When it's been ported to a winform it doesn't work on the GetResponse() call. I think it probably needs credentials but not sure what to use, tried a few ids w/o any luck.
9
3265
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 time. Please help! Dayne
0
2921
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 Winform code --------------- Browser.DocumentHTML = ""; string HTMLData="";
3
2776
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 in c#. Is it possible to do it through xml serialization ? THanks, --Emily *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
0
1033
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. I don't get any debug errors from IE itself (via IEDebug). Does anyone have any idea why this would happen? As a standalone App, my control works fine. Is IE treating my control any differently?
8
2827
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 issue...also our clients would like to use a lot of client side events like sorting, searching text, save each row on tab out of a row, use the auto correct feature... after intial r&d we feel that using a Grid Control in WinForms would be a...
0
2007
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 thread(m_MainThread). 2. Then the non-UI thread runs and creates derived winform and holds a reference to the winform. NOTE: I don't call Application.Run() because I don't need a message pump on this "hidden form" in my application. I rely on the...
8
3194
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 a database, it varies from record to record.. I've seen some classes on the net, but I want to use one from Microsoft, so I Added a reference Microsoft Word 9.0 object library and done:
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8825
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6163
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.