How can I saved page content to file?

  • Thread starter Thread starter arkgroup
  • Start date Start date
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
 
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
 
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.
 
Back
Top