Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I scrape a rendered .aspx page and email it?

Posted on 2009-05-12
8
Medium Priority
?
662 Views
Last Modified: 2012-05-06
I wish to scrape whats rendered ona results page and email it.  This includes results from a form view, textbox controls, dynamically generated tables etc.  I basically want to do a screenshot or send the infiormation that is rendered as a text file.

I can scrape the page thus far, but not the rendered data.
0
Comment
Question by:devnewbee
[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
8 Comments
 
LVL 7

Expert Comment

by:dineesh
ID: 24365108
Hi

Generate a PDF or an MDI and attach it to the email.

regards
Dinesh
0
 
LVL 7

Expert Comment

by:urir10
ID: 24365159
Read this:
http://www.csharpfriends.com/Articles/getTip.aspx?articleID=210

This example is asking you for an input url but you can change it to take the current page. The code puts the whole page in the string variable which you can then email.
0
 
LVL 4

Accepted Solution

by:
j_s_kelley earned 1500 total points
ID: 24365290
I am not clear on exactly what you are looking for.  If you want the raw HTML, you need to look in the PreRender event for the page.  You can do this by overriding the Render method on the page.


        protected override void Render(HtmlTextWriter htmlWriter)
        {
            StringBuilder sb = new StringBuilder();
            HtmlTextWriter tw = new HtmlTextWriter(new System.IO.StringWriter(sb));
            base.Render(tw);
            string strHTML = sb.ToString();
 
            // Here you can do what you wish with the HTML
            htmlWriter.Write(strHTML);
        }

Open in new window

0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

Author Comment

by:devnewbee
ID: 24365455
Here is my code for the finish button on this wizard.  I get this to work, but only scrapes the page and not the control values on the final step of the wizard.  
    protected void psWizard_FinishButtonClick(object sender, WizardNavigationEventArgs e)
    {
        {
            MailMessage mail = new MailMessage();
            mail.To = "test344@gmail.com";
            mail.From = "do-not-reply@gmail.com";
            mail.Subject = "this is a test email.";
            string url = "http://test.geopac.com/screen/";
            mail.Body = HttpContent(url);
            mail.BodyFormat = MailFormat.Html;
            mail.UrlContentBase = url;
            SmtpMail.SmtpServer = "relay.geopac.com";  
            SmtpMail.Send(mail);
        }
 
      
        dsInsert.Insert();
        Session["MyInsert"] = true;
        
    }
    private string HttpContent(string url)
    {
        WebRequest objRequest = System.Net.HttpWebRequest.Create(url);
        StreamReader sr = new StreamReader(objRequest.GetResponse().GetResponseStream());
        string result = sr.ReadToEnd();
        sr.Close();
        return result;
        Response.Redirect("~/confirmation.aspx");
    }
}

Open in new window

0
 

Author Comment

by:devnewbee
ID: 24365572
J_s_kelley:  I cane use the code above, but how do I call for it in the mail.body code of my mail code?
0
 
LVL 7

Expert Comment

by:urir10
ID: 24365590
You cant call it you have to do it in the Render method of the page.
0
 

Author Comment

by:devnewbee
ID: 24365681
Ok, so what happens is my user go through a wizard and the final page of the wizard display a results page based on some answers to dropdown etc on the page prior.  I just want to send that results information in an email once the user enters their email address in a textbox.

If I actually go to file and use save as (.txt) I see all of the results page formatted in a nice format (not real source).  This is kind of what I am looking for in that I want the user to either see a text file, and html file or a .pdf snapshot of the page as rendered once they click the finish button.
0
 

Author Comment

by:devnewbee
ID: 24366188
Thanks urir.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

722 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