How can I saved page content to file?

A

arkgroup

I am generating asp.net page and need to send content of this page
(html) via email as attachment.
I have tried:
System.Web.HttpContext.Current.Request.SaveAs(Server.MapPath(".") + "\
\test.html", true);

but it has no actual page content.

Thanks
 
G

Guest

The request object is what is requesting your page, that will not help at all.
The Page class derives from Control, and this offers the RenderControl method.
If you search around you can find some examples of how to use that , handle
errant <FORM> tags, and save the resulting HTML to a file if desired, to be
used as an attachment.
Peter
 
R

Ralph

I am generating asp.net page and need to send content of this page
(html) via email as attachment.
I have tried:
System.Web.HttpContext.Current.Request.SaveAs(Server.MapPath(".") + "\
\test.html", true);

but it has no actual page content.

Thanks

I usually do the following to get the html from a page.

StringBuilder sb = new StringBuilder();
HtmlTextWriter htw =new HtmlTextWriter(new StringWriter(sb));

// Render the page to it
Render(htw);

string strHTML = sb.ToString();

you can then use strHtml as the body of an email or for saving to a
file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top