Solved

Print HTML documents from VB.NET Windows application

Posted on 2003-11-26
10
5,821 Views
Last Modified: 2012-06-27
Hi

Can somebody pls. tell me how to print HTML documents from VB.NET Windows application WITHOUT GETTING PRINT DIALOG BOX .
I have two problems
One is how to read HTML document using VB.NET windows application i.e. if i want to read value from an Input Text box from an HTML document then how to read it
Secondly how to print html docs without getting print dialog box control, basically i'm using WebBrowser control to load and view but i want to know hot to read and print.
I tried with Window.Print in this but it always gives me Print dialog box.
Pls. Help

Arvind
0
Comment
Question by:arvindb1
10 Comments
 
LVL 18

Accepted Solution

by:
testn earned 480 total points
Comment Utility
1. Do something like this
    Dim doc As mshtml.HTMLDocument = WebBrowser.Document()
    Dim text As String = doc.all.text1.value

2. Use SHDocVW ExecWB command
WebBrowser.ExecWB
(SHDocVw.OLECMDID.OLECMDID_PRINT,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER)
0
 
LVL 5

Author Comment

by:arvindb1
Comment Utility
1. I tried like this
            Dim doc As New mshtml.HTMLDocument
            doc.open("f:\temp\abc.htm")
            Dim textstr As String = doc.all.txtfirst.value

But gets the error-- couldnt find element (txtfirst is a textbox in my htm file)
Is this the way to load document without using Webbrowser, i need to load htmldocument to read without using webbrowser

2. I used it using WebBrowser only and gets this error--- trying to revoke a drop target that has not been registered.

Arvind
0
 
LVL 5

Author Comment

by:arvindb1
Comment Utility
I tried first one with WebBrowser also but it gives error Object Reference not set to an instance of an object at Dim textstr As String = doc.all.txtfirst.value

Second problem i got some solution like this
        AxWebBrowser1.Navigate("F:\Help\testwinapp\test\abc.htm")
        While AxWebBrowser1.QueryStatusWB(SHDocVw.OLECMDID.OLECMDID_PRINT) <> SHDocVw.OLECMDF.OLECMDF_SUPPORTED + SHDocVw.OLECMDF.OLECMDF_ENABLED
            Application.DoEvents()
        End While
        AxWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER)

then i'm able to print without prompt.
but first problem still remains.
Thanks a lot
Arvind
0
 
LVL 5

Author Comment

by:arvindb1
Comment Utility
Hi Testn

Now the problem in printing is that if i put this into loop and try to print many html documents then i'm able to print only one document and rest all prints gets abondoned, any  way to control this??

Second problem still remains, i'm not able to read values from html after loading.
Pls. help
Arvind
0
 
LVL 5

Author Comment

by:arvindb1
Comment Utility
Hi Testn

Points are all yours if you just help me in this.
I want to read a preformatted mail (you can even suggest what format shall i use), currently i'm thinking about HTML format which has got some fields filled up and i want to read this mail programmatically and fetch the values from different fields and enter into the database. I'll accept any possible solution which can solve this problem.

Actually the flow is -- i will send a formatted mail to users who will fill up the fields in the mail itself while replying and then i have to fetch those values from mail and update the database.
Pls. suggest, how to acheive this minimizing the possibility of errors.

Thanks
Arvind Bansal

0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 5

Assisted Solution

by:kuzco
kuzco earned 20 total points
Comment Utility
hmm.. A very cool idea to do things ! well anyway here's what i would suggest .

Write a custom XSL transform for transforming the body part of the HTML document into an appropriate XML document since you know that the HTML document is not going to be manipulated in the client side. IF the clients are just going to type in values and then send the mail back to you, this shouldn't be a problem. You XSL transform should take the body of the mail, take the body part or just a DIV tag which contains all the respective FORM elements say something like "Name", "Age" or something else and then apply the transform to get the XML back in another standard format.

Once you get the XML out, all you have to do is to write a SP which will take the XML as input and then use SQL XML functionality to put the details into appropriate tables. Or rather you could also load the XML into a dataset and then persist the same ... From here, the option of persisting mechanism is upto you !

Hope this helps.
0
 
LVL 18

Assisted Solution

by:testn
testn earned 480 total points
Comment Utility
You can add additional arguments in ExecWB to make the API wait until it finishes printing by passing the third argument

PRINT_WAITFORCOMPLETION (0x02)

http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reference/methods/execwb.asp
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=f11c8df9.0305070813.5eefa706%40posting.google.com&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26q%3DPRINT_WAITFORCOMPLETION%2Bc%2523%26sa%3DN%26tab%3Dwg

It should look like

            Dim missing As Object = Type.Missing
            Dim wait As Object = CShort(2);
        AxWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,wait,missing)
0
 
LVL 18

Assisted Solution

by:testn
testn earned 480 total points
Comment Utility
About first problem.... I guess that you try to access the data right away. The DOM may not exist yet. You might need to wait until it finishes loading i.e. use NavigateComplete to detect that.
0
 
LVL 8

Expert Comment

by:nishikanth
Comment Utility
0
 
LVL 5

Author Comment

by:arvindb1
Comment Utility
Hi testn
i tried that but it still prints one page only, anyway other part is OK.
Thanks for your help. I'm awarding you the points as i dont see any more comments coming out to solve this. Anyway thanks a lot.
Arvind
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now