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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top