不支持GridView导出到PDF错误

时间:2016-05-19 14:14:23

标签: c# pdf gridview

以下是 Export ActionResult PDF

List<DailySum> lstDailySum = db.DailySum.Include(x => x.codeACl).Include(x => x.codeCou).Include(x => x.codeAgc).Include(x => x.AInfo).ToList();

GridView gv = new GridView();
if (Session["Paging"] == null)
{
    gv.DataSource = lstDailySum;
}
else
{
    gv.DataSource = Session["Paging"];
}

gv.DataBind();
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=DailySumExport.pdf");
Response.ContentType = "application/pdf";
Response.Charset = "";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gv.RenderControl(htw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();

现在,当我尝试导出到Excel时,此功能正常,但当我尝试导出为PDF时,我收到此错误消息:

  

Adob​​e Acrobat Reader DC无法打开&#39; DailySumExport.pdf&#39;因为它不支持文件类型或文件已损坏(例如,它是作为电子邮件附件发送的,并且未正确解码)。

非常感谢有关如何解决此问题的任何帮助。

感谢。

0 个答案:

没有答案