Printing webpage using URL 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 lotusnotes 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 do not know how to print it (and in a nice format)

any help would be appreciated
    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();

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Why not dump it to a web page and immediately after call the javascript print function?

Author

Commented:
okay with me, but do not know how to do that.
Top Expert 2009
Commented:
Next step is to read the response.

  var reader = new StreamReader(_WebStream);
  string text = reader.ReadToEnd();

Then you have the HTTP content in text, and need to format it up.


Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Commented:
Then write the javascript after your write the text variable that mrjoltcola describes.

You could append the javascript to the text variable after your stream.

Author

Commented:
now what?

    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();

Open in new window

Commented:
Response.Write(text) or I would create a label on the page and set its text to the text variable.

Commented:
text += @"<script language="Javascript">function printpage() window.print();}/script>"

Author

Commented:
sorry, I'm very new at this... you guys lost me on the last 2 lines.

Response.Write(text) or I would create a label on the page and set its text to the text variable
give an error
Response in underlined saying does not exist in current context

and
text += @"<script language="Javascript">function printpage() window.print();}/script>"
is this 1 line of code, I am getting underlined RED for the whole thing
Commented:
text += @"<script language=""Javascript"">window.print();</script>" ;

Actually, use a literal control.

Author

Commented:
dumn question number 100000,
it ran without any errors... but nothing printed... what am I missing?

Commented:
is your page displaying your text?

Author

Commented:
the only thing that launches is my normal windows form... nothing else comes up

using System;
using System.IO;
using Domino;
using System.Configuration;
using System.Windows.Forms;
using System.DirectoryServices.AccountManagement;
using lotus;
using System.Net;
using System.Data;
using Microsoft.CSharp;
using System.Web;
using System.Xml;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Text;
using System.Diagnostics;
using Microsoft.JScript;
    public frmMain()
    {
        InitializeComponent();
        SetFields();
        SetEmails();
        //string IPAddress = GetIPAddress(sHostname);

        //test area**********************************************************
        FindWebPage();
        //*******************************************************************

    }

  //private string GetIPAddress(string sHostName)
    //        {
    //        IPHostEntry ipEntry = Dns.GetHostEntry(sHostname);
    //        IPAddress [] addr = ipEntry.AddressList;
    //        string sIPAddress = addr[0].ToString();
    //        return sIPAddress;
    //        }

    [STAThread]

    public static void Main()
    {
        frmMain main = new frmMain();
        Application.Run(main);
    }

    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();

        text += @"<script language=""Javascript"">window.print();</script>";

Open in new window

Commented:
Two things.  

1. I made the assumption that you were using a web site, not a windows application, my apologies.  The Javascript isn't what you want to use here.

2.  Step through your code and verify that the text variable is actually being populated with data.  Then, worry about printing your form.

Author

Commented:
the text variable IS being populated... but I'm looking it at the LOCALS windows so I can't get a good picture of whats in there.

since I'm in a windows app, what is my next step.

very sorry for all these questions

Commented:
Place a label on your form and set its text to the text variable.  If you don't have room on the current form, open another and display the text there.

Author

Commented:
so I did that... apparently the information in there is all garbage.  dont even know how to describe it.

pasted below is only half of it.

Think this has something to do with my proxy?

// 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") ||
          localHostOrDomainIs(host, "axiweb02.isc.cw.net") ||
          localHostOrDomainIs(host, "test.geoaccess.com") ||
          localHostOrDomainIs(host, "www.aetnaushc.com") ||
          localHostOrDomainIs(host,

Commented:
hmmm...not sure if it's the proxy or not, it may be the way you're getting the data.  I'm not sure about that--sorry.
Top Expert 2009

Commented:
That isn't garbage, that is the page itself. What you listed above is Javascript content from the page that you requested.

So you accomplished what you asked, but I think what you want to do is render the visible portion of the page and include that in the email.
Top Expert 2009

Commented:
No need to delete this one. Experts have already put in time helping you here. You are free to open a related question, but this one shouldn't be deleted.

Author

Commented:
shows what I know. Thank you.

I removed the new post and will keep this one only.

Since you are correct, and I want to return the visible portion of the page, how should I go about doing this?
Top Expert 2009

Commented:
>> I removed the new post and will keep this one only

No, I didn't mean that. You are welcome to open a new question. You can open as many questions as you like as long as they are not duplicates. Please just properly close this one.

The way I see it, you accomplished your original question's goal, but now you want something a bit more specific, like how to properly render the page in an email. That is a separate issue, so I think a new question may be in order, as it will bring in new experts.

Author

Commented:
ok, thank you
Top Expert 2009

Commented:
Welcome. There is also a "Ask a related question" link on this one that automatically refers back to this one for the new question.

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