WebPage to Excel Conversion Error

  • Thread starter Thread starter Stephen
  • Start date Start date
S

Stephen

Hi,
I am converting webpage to Excel and its within a try catch block
it creates an Excel Spreadsheet but at the sametime it gives this error

ExceptionMessage:Thread was being aborted.

Please advice,
Stephen
 
Post some snippet code where you are getting the error
Patrick
 
Are you using Response.Redirct to get to the Excel page?
If so, this may be the root of your problem, try adjusting the 2nd (boolean)
parameter to Response.Redirect.
 
Hi Patrick,

Here is the code snippet:

Private Sub btnExcel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExcel.Click
Try
Dim dsExcel As New DataSet
dsExcel = dbData.getCDWorldAll
If Not dsExcel Is Nothing Then
ConvertToExcel(dsExcel, Response)

End If

Catch ex As Exception
errLog.LogIt("Creating Excel SpreadSheet Error", ex, "")

End Try
end Sub

Public Shared Sub ConvertToExcel(ByVal ds As System.Data.DataSet, ByVal
response As System.Web.HttpResponse)

response.Clear()
response.Charset = ""
response.ContentType = "application/vnd.ms-excel"
Dim stringWrite As New System.IO.StringWriter
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
Dim dg As New System.Web.UI.WebControls.DataGrid
dg.DataSource = ds.Tables(0)
dg.DataBind()
dg.RenderControl(htmlWrite)
response.Write(stringWrite.ToString)
response.End()

End Sub

I mean it does whats required but at the sametime goes into "catch" and
shows error.
Thanks,
Stephen
 
Hi Steve,

thanks for the reply, I have tried both scenarios
1. display (excel) within the same page
2. response.redirect to another page
both show the same error

Please advice,
Stephen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top