A day with .Net

My day to day experince in .net

Email an aspx page without rendering to user

Posted by vivekcek on July 21, 2009

                                   One day i got a work,to send an aspx page as email with out opening it or rendering it to the user.The page was dyanmic one shows some data from datbase.So i need to execute the page and generate it HTML and then i can mail it,Mailing can be done by the Mail class avilable in .net.So the problem shortend to execute the page in back and get its HTML as formated string.This can be done by the following function.

public static string GetHTML(HttpServerUtility server, string url)
System.IO.StringWriter writer = new System.IO.StringWriter();
server.Execute(url, writer);
return writer.ToString();

The above function can be called by

GetHTML(HttpContext.Current.Server, lastUrl);


string lastUrl="~/comm/myfolder/mypage.aspx?sampleid=1"

Please include Sytem.IO and Sytem.Net namespaces


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s