0

Hi, I am writting a program to let user generate excel file from the datagrid in web page. Below is the codes:

 Private Sub ConvertToExcel(ByVal Data As ProductionScheduleData)

            Dim stringwrite As New System.IO.StringWriter
            Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringwrite)

            GridExcel.RenderControl(htmlWrite)
            Response.Clear()
            Response.ClearContent()
            Response.ClearHeaders()
            Response.BufferOutput = True
            Response.AddHeader("Content-Disposition", "attachment;filename=" + "ProductionSchedule" + ".xls")
            Response.Charset = ""
            Response.ContentType = "application/vnd.ms-excel"
            Response.Write(stringwrite.ToString())
            Response.Flush()
            Response.Close()
            Response.End()
 End Sub

The excel file was successfully generated. My problem is, after the file generated, the web page seem like still processing something. I can't do the next action, unless I reentry that page with new action. Did I miss something in my codes? It seem like the response does not fully close, or something else. I said that because the problem occured when it reach the codes line "Response.AddHeader".

Anyone can helps? Thanks in advanced.

2
Contributors
1
Reply
6
Views
5 Years
Discussion Span
Last Post by LastMitch
0

It seem like the response does not fully close, or something else. I said that because the problem occured when it reach the codes line "Response.AddHeader".

You can change this:

Response.AddHeader("Content-Disposition", "attachment;filename=" + "ProductionSchedule" + ".xls")

to this:

Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.xls", fileName));

Edited by LastMitch: grammer

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.