I've searched virtually every possible place I can to find an answer. I have come up empty. I am using the typical code to export a datagrid to Excel. However, when the "File Download" dialog re-appears if clicking the Open button. What am I missing? If I remove the Response.Addheader line, everything works as expected. I would prefer to either force a filename or leave it workbook unnamed with a status of unsaved. My code follows:
If anyone requires additional info, please let me know. Thanks for your help.
Code:
Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
Dim s, f, g, h, w, o, pSql, pFarm, pAppName As String
s = lbSql.Items.Item(0).Value
f = lbSql.Items.Item(1).Value
w = lbSql.Items.Item(2).Value
g = lbSql.Items.Item(3).Value
h = lbSql.Items.Item(4).Value
o = lbSql.Items.Item(5).Value
pSql = s & f & w & g & h & o
pFarm = farmselect()
pAppName = dd_AppName.SelectedItem.ToString
ClearControls(dgResults)
Response.Clear()
Response.AppendHeader("content-disposition", "attachment;filename=" & pAppName.ToString & ".xls")
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
EnableViewState = False
Dim stringWrite As New System.IO.StringWriter()
Dim htmlWrite As New HtmlTextWriter(stringWrite)
dgResults.AllowCustomPaging = False
dgResults.AllowPaging = False
dgResults.AllowSorting = False
exp_Status = False
Bind_dgResults(pSql)
dgResults.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.Flush()
Response.End()
End Sub
If anyone requires additional info, please let me know. Thanks for your help.