Solved

Print HTML documents from VB.NET Windows application

Posted on 2003-11-26
10
5,839 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
ID: 9829719
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
ID: 9829962
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
ID: 9830024
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 5

Author Comment

by:arvindb1
ID: 9841778
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
ID: 9902900
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
 
LVL 5

Assisted Solution

by:kuzco
kuzco earned 20 total points
ID: 9903494
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
ID: 9903862
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
ID: 9904414
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
ID: 9918569
0
 
LVL 5

Author Comment

by:arvindb1
ID: 9976997
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 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