Print webpage from windowsform in c#

solarissf
solarissf used Ask the Experts™
on
Hello All,

Stuck on this and driving me crazy.

The end goal is to print an email in lotus notes automatically.  Already found the universalID of specific email.

Now I am trying to return url as a webpage through a proxy(using UNIVERSAL ID) and print it.  Due to fact that no matter what I try I cannot get lotusnotes to print it automatically.

I've been able to retreive webpage, but its the javascript I believe.

I am looking to print what the view is as if you looked at the website and hit print.  Not the code behind it.  

If I put the results of what I found in a form txtbox I only see the script of the webpage.

any ideas?

    public void FindWebPage()
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.msn.com");
        WebProxy myproxy = new WebProxy("http://autoproxy:81", false);
        myproxy.BypassProxyOnLocal = false;
        request.Proxy = myproxy;
        request.Method = "GET";
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();


        System.IO.Stream _WebStream = response.GetResponseStream();
        var reader = new StreamReader(_WebStream);
        string text = reader.ReadToEnd();
        txtEmailTest.Text = text;

Open in new window


here is the output
// Prudential Internet Access Services, report problem to SPOC @ 1-888-PRU-PRU9
// Dynamic Automatic Proxy Config - PLEASE DO NOT MODIFY
// Configuration Generated at Mon May 16 18:17:14 2011 UTC - proxy.pac : default
// Client IP: 48.27.193.68 | BROWSER:  | Region: default
ftpProxyAll    = "PROXY " + "48.19.199.100:8080"   + "; PROXY " + "48.135.149.100:8080" ;
gopherProxyAll = "PROXY " + "48.19.199.100:8080"   + "; PROXY " + "48.135.149.100:8080" ;
httpProxyAll   = "PROXY " + "48.19.199.100:8080"   + "; PROXY " + "48.135.149.100:8080" ;
httpsProxyAll  = "PROXY " + "48.19.199.100:8080"   + "; PROXY " + "48.135.149.100:8080" ;
trustProxyAll  = "PROXY " + "48.113.204.143:8080" + "; PROXY " + "48.114.150.143:8080" ;
internalProxyAll = "PROXY " + "" + "; PROXY " + "" ;
function FindProxyForURL(url, host) {
      if ( isPlainHostName(host) )
            return "DIRECT";
        else if ( localHostOrDomainIs(host, "prudential.your-locator.com") ||
          localHostOrDomainIs(host, "pruhomes.prudential.com") ||
        shExpMatch(host, "207.87.15.28") ||
          localHostOrDomainIs(host, "www.vicinity.com") ||
          localHostOrDomainIs(host, "myhr-ess.prudential.com") ||
          localHostOrDomainIs(host, "prudential.vicinity.com") ||
          localHostOrDomainIs(host, "www.geoaccess.com") ||
          localHostOrDomainIs(host, "advantage.prudential.com") ||
          (localHostOrDomainIs(host, "www.ups.com") && 
           (url.substring(0, 5).toLowerCase() == "http:")) ||
          (localHostOrDomainIs(host, "wwwapps.ups.com") && 
           (url.substring(0, 5).toLowerCase() == "http:")) ||
          (localHostOrDomainIs(host, "www.dhl.com") && 
           (url.substring(0, 5).toLowerCase() == "http:")) ||
          localHostOrDomainIs(host, "www.fedex.com")  ||
          localHostOrDomainIs(host, "www.axi.americanexpress.com") ||
          localHostOrDomainIs(host, "www.cibt.com") ||
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Throw a WebBrowser control onto your form, load the page you want into it (even if it's a temp file that you saved the downloaded source to) and call the Print method.

Author

Commented:
starting point for loading page onto control form?
Add the Web Browser control to your form via the toolbox like you would any other control.
Change your code to something like this:
 
...
//txtEmailTest.Text = text;
string tempFile = "page_to_print.htm";
File.WriteAllText(tempFile, text);
webBrowser1.Url = new System.Uri(Path.GetFullPath(tempFile));
webBrowser1.Print();

Open in new window

The Web Browser control has other methods to show the print dialog as well if you want.

Author

Commented:
thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial