ASP.NET create excel file fails

woodhzmr

New Member
I have the following method to create a excel file.\[code\]Private Sub ExportToExcel() Dim dv As DataView = CType(SqlDataSourceExel.Select(DataSourceSelectArguments.Empty), DataView) Dim dt As DataTable = dv.ToTable() Dim query = From r In dt.AsEnumerable() Select New With { .callid = r.Field(Of Decimal)("callid"), .Problem = r.Field(Of String)("Problem"), .Details = r.Field(Of String)("Details"), .Entered_Date = r.Field(Of DateTime)("Entered_Date"), .Name = r.Field(Of String)("Name"), .comments = "" } Dim sb As StringBuilder = New StringBuilder() Dim fileName As String = "list.xls" 'sb.Append("Call Id \t Problem \t Details \t Entered_Date & \t Logged by \t Comments") For Each row In query sb.Append(row.callid & "\t" & row.Problem & "\t" & row.Details & "\t" & row.Entered_Date & "\t" & row.Name & "\t" & row.comments & "\n") Next HttpContext.Current.Response.Clear() HttpContext.Current.Response.ContentType = "Application/x-msexcel" HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + fileName) HttpContext.Current.Response.Write(sb.ToString()) HttpContext.Current.Response.End()End Sub\[/code\]I'm getting following error when the code is executed. How can I fix it?Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.
 
Back
Top