Solved

Print HTML documents from VB.NET Windows application

Posted on 2003-11-26
10
5,846 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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