Click here to Skip to main content
12,893,190 members (56,913 online)
Rate this:
Please Sign up or sign in to 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.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/ms-excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html;       charset=utf-8\" />");
Posted 17-Sep-12 3:14am
Marcus Kramer 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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

//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;
        ////Get the HTML for the control.
        //HttpContext.Current.Response.ContentType = "application/";
        //HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName + ".xlsx");
        ////this.EnableViewState = false;
        //TimeSpan elapsed = sw1.Elapsed;

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

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 17 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100