On this article you'll learn how to catch the output HTML of an asp.net page.
Terms of Agreement:
By using this article, you agree to the following terms...
You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
You may link to this article from another website, but ONLY if it is not wrapped in a frame.
You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
There are several reasons to get the HTML code of a ASP.NET page.To do this you will need to use Render method.Put the following code on the page you want to have it's HTML output.
'*****Code starts here******
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim OUTPUT_FILENAME As String = "Output.html"
Dim renderedOutput As StringBuilder = Nothing
Dim strWriter As IO.StringWriter = Nothing
Dim tWriter As HtmlTextWriter = Nothing
Dim outputStream As IO.FileStream = Nothing
Dim sWriter As IO.StreamWriter = Nothing
Try
'create a HtmlTextWriter to use for rendering the page
renderedOutput = New StringBuilder
strWriter = New IO.StringWriter(renderedOutput)
tWriter = New HtmlTextWriter(strWriter)
MyBase.Render(tWriter)
'save the rendered output to a file
filename = Server.MapPath(".") & "\" & "Output.html"
outputStream = New IO.FileStream(filename, _
IO.FileMode.Create, IO.FileAccess.ReadWrite, IO.FileShare.ReadWrite)
sWriter = New IO.StreamWriter(outputStream)
sWriter.Write(renderedOutput.ToString())
sWriter.Flush()
writer.Write(renderedOutput.ToString())
Finally
'clean up
If (Not IsNothing(outputStream)) Then
outputStream.Close()
End If
If (Not IsNothing(tWriter)) Then
tWriter.Close()
End If
If (Not IsNothing(strWriter)) Then
strWriter.Close()
End If
End Try
End Sub
'*****Code ends here******
Now you have the output as a seprate file.You can mail it to a desired address.Or do anything you want.
Farshad Jan-e Aziz, for goodness sake, resize your image down. This is a coding site not facebook. (If this comment was disrespectful, please report it.)
code is nice. you can describe it some what better and put the code in proper aligned format. so tat every one can understood easily... thank you (If this comment was disrespectful, please report it.)
Works Fine! Thanks! (If this comment was disrespectful, please report it.)
Add Your Feedback
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular article, please
click here instead.)