Solved

Print HTML documents from VB.NET Windows application

Posted on 2003-11-26
10
5,849 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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 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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

707 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