Save an Excel file, created from a DataGrid, programmatically..

Discussion in 'Software' started by tapasmahata, Jan 12, 2008.

  1. tapasmahata

    tapasmahata

    Joined:
    Jan 12, 2008
    Messages:
    7
    Location:
    Kolkata
    Hi,

    I need to Save my Excel File which I created from a DataGrid to my Hard Drive(C:\) using the C#.NET codes. It can be saved by the dialog box but I don't need that....I need the prior..

    SomeOne Please Help Me....

    Thanks

    Tapas Mahata

    Code Sample :

    public void ExportToSpreadsheet(DataGrid dg, string name)
    {

    Response.ClearContent();
    Response.AddHeader("content-disposition", "attachment; filename=" + name);
    Response.ContentType = "application/excel";
    System.IO.StringWriter sw = new System.IO.StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(sw);
    dg.RenderControl(htw);
    Response.Write(sw.ToString());
    Response.End();


    }
     
    tapasmahata, Jan 12, 2008
    #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. Priya
    Replies:
    1
    Views:
    3,206
    Pavel A.
    Jul 31, 2004
  2. Eric Yun
    Replies:
    1
    Views:
    1,106
    Beverly Howard [Ms-MVP/MobileDev]
    Sep 15, 2004
  3. Pankaj Ankam
    Replies:
    1
    Views:
    850
    Walter Roberson
    Nov 26, 2004
  4. =?Utf-8?B?UmljaGFyZA==?=
    Replies:
    1
    Views:
    3,433
    AnandaMS
    Dec 14, 2010
  5. dumbrock
    Replies:
    4
    Views:
    624
    dumbrock
    Oct 21, 2004
Loading...

Share This Page