A
Alex A.
I got some code off of dotnetjunkies.com to export a datagrid to excel.
Everything works fine when I test it on my localhost, but when I move
it to a server it doesn't do anything (no errors, just a plain
postback).
What am I missing?
Is it a security issue?
Any help appreciated and here the code:
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ContentType =
"application/vnd.ms-excel"
HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename=" & saveAsFile & ".xls")
' Remove the charset from the Content-Type header.
HttpContext.Current.Response.Charset = ""
'HttpContext.Current.Response.WriteFile("style.txt")
' Turn off the view state.
grid.EnableViewState = False
Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
grid.RenderControl(hw)
' Write the HTML back to the browser.
HttpContext.Current.Response.Write(tw.ToString())
' End the response.
HttpContext.Current.Response.End()
Everything works fine when I test it on my localhost, but when I move
it to a server it doesn't do anything (no errors, just a plain
postback).
What am I missing?
Is it a security issue?
Any help appreciated and here the code:
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ContentType =
"application/vnd.ms-excel"
HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename=" & saveAsFile & ".xls")
' Remove the charset from the Content-Type header.
HttpContext.Current.Response.Charset = ""
'HttpContext.Current.Response.WriteFile("style.txt")
' Turn off the view state.
grid.EnableViewState = False
Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
grid.RenderControl(hw)
' Write the HTML back to the browser.
HttpContext.Current.Response.Write(tw.ToString())
' End the response.
HttpContext.Current.Response.End()