hi,
i am usig aspose.cells to create a excel file and iam trying to allow the user to download that file. while doing that its giving the error
Server cannot append header after HTTP headers have been sent.
its working fine when separate the code and paste in two buton events.
my code is:
Dim workbook As Workbook = New Workbook()
workbook.Worksheets.Add()
Dim worksheet As Worksheet = workbook.Worksheets(0)
Dim RS As SqlCommand = New SqlCommand()
Dim strSQL As String
Dim MyConn As SqlConnection = New SqlConnection()
MyConn.ConnectionString = ConfigurationManager.ConnectionStrings("Small_ScanConnectionString").ToString
If GridView1.Visible = True Then
strSQL = "exec usp_rpt_SubmissionReportOne '" & User.Identity.Name.ToString & "', '" & textBoxStartDate.Text & "','" & textBoxEndDate.Text & "'"
RS.CommandText = strSQL
RS.Connection = MyConn
RS.CommandType = Data.CommandType.Text
MyConn.Open()
Dim newDataSet As DataSet = New DataSet()
Dim newDataTable As DataTable = New DataTable()
Dim newDataAdapter As SqlDataAdapter = New SqlDataAdapter(RS)
newDataAdapter.Fill(newDataTable)
worksheet.Cells.ImportDataTable(newDataTable, True, "A2")
workbook.Save(System.Configuration.ConfigurationManager.AppSettings("generatedReportPath") & Session.SessionID & ".xls")
MyConn.Close()
End If
If GridView2.Visible = True Then
strSQL = "exec usp_rpt_SubmissionReportTwo '" & User.Identity.Name.ToString & "', '" & textBoxStartDate.Text & "','" & textBoxEndDate.Text & "'"
RS.CommandText = strSQL
RS.Connection = MyConn
RS.CommandType = Data.CommandType.Text
MyConn.Open()
Dim newDataSet As DataSet = New DataSet()
Dim newDataTable As DataTable = New DataTable()
Dim newDataAdapter As SqlDataAdapter = New SqlDataAdapter(RS)
newDataAdapter.Fill(newDataTable)
worksheet.Cells.ImportDataTable(newDataTable, True, "A2")
workbook.Save(System.Configuration.ConfigurationManager.AppSettings("generatedReportPath") & Session.SessionID & ".xls")
MyConn.Close()
End If
System.Threading.Thread.Sleep(3000)
Dim fileName As String = Session.SessionID & ".xls"
Response.Clear()
Response.ContentType = "application/ms-excel"
Response.AddHeader("content-disposition", "attachment; filename=" & fileName) 'error is coming here
Response.TransmitFile("Reports\" & fileName)
Response.Flush()
thanks