类型的异常'System.OutOfMemoryException的' [英] An exception of type 'System.OutOfMemoryException'

查看:440
本文介绍了类型的异常'System.OutOfMemoryException的'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将数据导出到pdf文件,
但我有'类型的异常

I need to export data to pdf file , but I have `An exception of type

的System.OutOfMemoryException'出现在mscorlib.dll但在用户code没有处理

这是我的code

 using (StringWriter sw = new StringWriter())
    {
        using (HtmlTextWriter hw = new HtmlTextWriter(sw))
        {
            GridView ExportGrid = new GridView();
            ExportGrid.AllowPaging = false;
            List<Tayf.Models.Product> DataLst = new List<Tayf.Models.Product>();

            DataLst = HttpContext.Current.Cache["productcache"] as List<Tayf.Models.Product>;

            ExportGrid.DataSource = DataLst;//DataSet1 has all values without paging
            ExportGrid.AllowPaging = false;

            ExportGrid.DataBind();

            ExportGrid.RenderControl(hw);
            StringReader sr = new StringReader(sw.ToString());
            Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
            PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            pdfDoc.Open();
            XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
            pdfDoc.Close();
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Write(pdfDoc);
            Response.End();
        }
    }

我的数据是超过100万行的庞大无比,我需要的所有数据导出到一个文件

my data is Very huge over than 1 million row and I need to export all data in one file

推荐答案

随着你的数据是如此之大,也许你应该将数据分成许多部分,并将它们分别写入到PDF。

As your data is such big, maybe you should separate your data into many parts and write them into the pdf separately.

这篇关于类型的异常'System.OutOfMemoryException的'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆