All pastes #640640 Raw Edit

Untitled

public text v1 · immutable
#640640 ·published 2007-07-31 15:20 UTC
rendered paste body

Partial Class ExcelReport
    Inherits System.Web.UI.Page


Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
	Dim stringWriter As System.IO.StringWriter = New System.IO.StringWriter
	Dim htmlWriter As HtmlTextWriter = New HtmlTextWriter(stringWriter)
	MyBase.Render(htmlWriter)
	Dim html As String = stringWriter.ToString()
	Dim StartPoint As Integer = html.ToLower.IndexOf("<input type=""hidden"" name=""__viewstate""")
	If StartPoint >= 0 Then	'does __viewstate exist? 
	Dim EndPoint As Integer = html.IndexOf("/>", StartPoint) + 2
	Dim viewstateInput As String = html.Substring(StartPoint, EndPoint - StartPoint)
	html = html.Remove(StartPoint, EndPoint - StartPoint)
	Dim FormEndStart As Integer = html.IndexOf("</form>") - 1
	If FormEndStart >= 0 Then
	html = html.Insert(FormEndStart, viewstateInput)
	End If
	End If
	writer.Write(html)
End Sub


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
	Response.ContentType = "Application/x-msexcel"
	Response.AddHeader("content-disposition", "attachment; filename=" + "Report.xls")


	' Populate your GridView Here!
End Sub

Protected Overrides Sub OnError(ByVal e As System.EventArgs)
	CatchError("ExcelReport.aspx", Server.GetLastError().GetBaseException(), Session("ReviewID"), Session("UserID"), Session("FullName"), Me)
End Sub

End Class