locked
Asp.net Export to Excel from GridView in 2007 RRS feed

  • Question

  •  Hi, 

    Iam getting when export to excel in asp.net 
     
    The file you are trying to open is in a different format than specified by the file extension
     

    This my code

    Response.ClearContent();

                Response.ContentType = "application/octet-stream";
                Response.AddHeader("Content-Disposition", "attachment; filename=Test.xls");


                GridView excel = new GridView();
                excel.DataSource = dt;
                excel.DataBind();
                excel.RenderControl(new HtmlTextWriter(Response.Output));


                Response.Flush();
                Response.End();

    Thanks 

    Krishna

    Wednesday, June 26, 2013 6:45 AM

Answers

All replies