Gridview - Convert to Excel and Save on Server Automatically

J

John Walker

Hi,

I am using the following code to convert an asp.net 2.0 gridview to Excel.
When this happens the user will be prompted to either open the file, save it
to disk, cancel, etc., and it works fine but now there's a new requirement
whereby I'll need to have the gridview automatically saved as an Excel file
on the server's hard drive instead of being downloaded to the client browser.
Is there a way to accomplish that?

Dim resp As HttpResponse
resp = Page.Response
resp.ContentType = "application/download"
Page.EnableViewState = False
resp.Charset = String.Empty
resp.AppendHeader("Content-Disposition",
"attachment;filename=PerformanceRpt.xls")
Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
gv.AllowPaging = False
gv.RenderControl(hw)


Thanks,
John
 

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,997
Messages
2,570,239
Members
46,828
Latest member
LauraCastr

Latest Threads

Top