saving an html file from a code behind - ASP.NET
However if you really need to generate HTML output from an ASPX page it canbe easily done by overriding the Render method and capturing the output from
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter) ' *** Write the HTML into this string builder Dim sb As StringBuilder = New StringBuilder() Dim hWriter As HtmlTextWriter = New HtmlTextWriter(New StringWriter(sb)) MyBase.Render(hWriter) ' *** store to a string Dim PageResult As String = sb.ToString() ' *** Write it back to the server's HTTP Stream -' *** skip this if you don't want to display the rendered content writer.Write(PageResult).... PageResult now hold the HTML content you can write to diskdo whatever you want to with. End Sub This example goes to string but you can use a StreamWriter instead of stringbuilder to dump the output directly to file if you wish.
Same in C#:
protected override void Render(HtmlTextWriter writer)
{
// *** Write the HTML into this string builder
StringBuilder sb = new St…
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter) ' *** Write the HTML into this string builder Dim sb As StringBuilder = New StringBuilder() Dim hWriter As HtmlTextWriter = New HtmlTextWriter(New StringWriter(sb)) MyBase.Render(hWriter) ' *** store to a string Dim PageResult As String = sb.ToString() ' *** Write it back to the server's HTTP Stream -' *** skip this if you don't want to display the rendered content writer.Write(PageResult).... PageResult now hold the HTML content you can write to diskdo whatever you want to with. End Sub This example goes to string but you can use a StreamWriter instead of stringbuilder to dump the output directly to file if you wish.
Same in C#:
protected override void Render(HtmlTextWriter writer)
{
// *** Write the HTML into this string builder
StringBuilder sb = new St…