Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
When I run my Export to Excel, the Spreadheet contains data but if i send it via mail it becomes empty. Anyone know what may cause this?
the code is :

string attachment = "attachment; filename=att_Data.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";

StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html;       charset=utf-8\" />");
Response.Write(sw.ToString());
Response.End();
Posted
Comments
fjdiewornncalwe 17-Sep-12 9:27am    
You should probably show us the code where you create the email and attach the excel to it. If you have valid results from this code to a page then the problem is likely in the code where you either mail or attach the file to the mail.

1 solution

//Stopwatch sw1 = Stopwatch.StartNew();//1.85
        ////#region "Downloading excel file with Certificate Track data "
        //System.IO.StringWriter tw = new System.IO.StringWriter();
        //System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
        //DataGrid dgGrid = new DataGrid();
        //dgGrid.DataSource = objDataTable;
        //dgGrid.DataBind();
        ////Get the HTML for the control.
        //dgGrid.RenderControl(hw);
        //HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
        //HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName + ".xlsx");
        ////this.EnableViewState = false;
        //HttpContext.Current.Response.Write(tw.ToString());
        //sw1.Stop();
        //TimeSpan elapsed = sw1.Elapsed;
        //HttpContext.Current.Response.End();
        //System.Diagnostics.Process.Start(finalFileNameWithPath);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900