Gridview - Convert to Excel and Save on Server Automatically

Discussion in 'ASP .Net Web Controls' started by John Walker, Mar 6, 2009.

  1. John Walker

    John Walker Guest

    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
     
    John Walker, Mar 6, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sincethe2003
    Replies:
    2
    Views:
    569
    Craig Deelsnyder
    Jul 14, 2004
  2. Replies:
    1
    Views:
    393
  3. subhadip
    Replies:
    0
    Views:
    676
    subhadip
    Mar 28, 2007
  4. =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=

    Problem with Excel reports ::::Excel 2003 Migration To Excel 2007

    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=, Oct 5, 2007, in forum: ASP .Net
    Replies:
    15
    Views:
    1,606
    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=
    Oct 24, 2007
  5. eddie wang
    Replies:
    0
    Views:
    438
    eddie wang
    Oct 3, 2003
Loading...

Share This Page