Saving datagrid as Excel file

R

RSH

Hi,

Im using the code below to render a datagrid as an Excel file. It seems to
work fine when the user clicks on the Save button. But when they click on
the open button, it renders correctly but when the user attempts to save the
document from the browser...it saves it as an HTML file. Is there any way
to disable the Open button and force the user to save the file? Or some
other trick to make sure the file saves as a type xls?

Response.Clear()

Response.Buffer = True

Response.ContentType = "application/vnd.ms-excel"

Response.Charset = ""

Response.AddHeader("Content-Disposition",
"attachment;filename=ClientAlertExport" & Now() & ".xls")

Dim SW As System.IO.StringWriter = New System.IO.StringWriter

Dim HTW As System.Web.UI.HtmlTextWriter = New
System.Web.UI.HtmlTextWriter(SW)

DataGrid1.RenderControl(HTW)

Response.Write(SW.ToString())

Response.End()



Thanks,

Ron
 

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

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top