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
    Likes Received:
    0
    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. Advertisements

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 (here). After that, you can post your question and our members will help you out.