Avatar of Stephen Forero
Stephen Forero
Flag for United States of America asked on

Printing webpage using URL in c#

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

C#

Avatar of undefined
Last Comment
mrjoltcola

8/22/2022 - Mon
edemcs

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

ASKER
okay with me, but do not know how to do that.
SOLUTION
mrjoltcola

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
edemcs

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.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Stephen Forero

ASKER
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

edemcs

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

text += @"<script language="Javascript">function printpage() window.print();}/script>"
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Stephen Forero

ASKER
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
ASKER CERTIFIED SOLUTION
edemcs

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Stephen Forero

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

is your page displaying your text?
Your help has saved me hundreds of hours of internet surfing.
fblack61
Stephen Forero

ASKER
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

edemcs

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.
Stephen Forero

ASKER
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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
edemcs

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.
Stephen Forero

ASKER
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,
edemcs

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.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
mrjoltcola

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

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.
Stephen Forero

ASKER
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?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
mrjoltcola

>> 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.
Stephen Forero

ASKER
ok, thank you
mrjoltcola

Welcome. There is also a "Ask a related question" link on this one that automatically refers back to this one for the new question.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck