Important alert: (current site time 7/15/2013 10:04:19 PM EDT)
 

article

Catch HTML output of current page (With full code)

Email
Submitted on: 3/14/2008 2:47:57 PM
By: Farshad Deliri  
Level: Advanced
User Rating: By 1 Users
Compatibility: ASP (Active Server Pages), HTML, VbScript (browser/client side)
Views: 24286
(About the author)
 
     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...   
  1. 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.
  2. 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.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. 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.


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Advanced category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

3/26/2008 2:17:29 PMGuardian666

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.)

 
9/27/2008 7:32:54 AMamitak

thank you

(If this comment was disrespectful, please report it.)

 
10/10/2008 12:45:10 AMThiyagarajan Easwaran

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.)

 
1/7/2010 2:02:59 AMukwebguy

Incorrect section - not ASP
(If this comment was disrespectful, please report it.)

 
1/7/2010 7:08:44 AMIndustria Virtual

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.)
 

To post feedback, first please login.