pdf文件和excel文件无法创建 [英] pdf file and excel file can't create

查看:104
本文介绍了pdf文件和excel文件无法创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



这里我尝试从datatble为mvc3应用程序创建一个pdf文件,它在c盘上创建本地,但是在发布之后它不是从我们的测试网站在c盘上创建



这是我的功能。



Hi All,

Here I tried to create a pdf file from datatble for an mvc3 application,It creates Locally on c drive,But after publishing it is not creating on the c drive from our testwebsite

Here is my function.

public JsonResult ExportToPdf()
        {
            string retval;
            DataTable dt = new DataTable();
            List<applicationvariables> _pvtList = new List<applicationvariables>();
            common obj_EditList = new common();
            dt = obj_EditList.getcardholders(0, "", "");

            try
            {
                Document document = new Document();
                string path = "c:\\";
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(path + "cardholderdetails.pdf", FileMode.Create));
                document.Open();
                //iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance("c://ggi logo.bmp");
                //document.Add(img);
                iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 8);
                //float[] columnDefinitionSize = { 22F, 22F, 12F, 7.75F, 7.77F, 7.77F, 7.77F, 7.77F, 10.88F, 10.88F, 10.88F, 4.75F, 7.77F, 7.77F, 7.77F, 7.77F, 7.77F, 7.77F, 9F };

                PdfPTable table = new PdfPTable(dt.Columns.Count);
                PdfPRow row = null;
                float[] widths = new float[] { 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f };

                table.SetWidths(widths);

                table.WidthPercentage = 100;
                int iCol = 0;
                string colname = "";
                Phrase p1Header = new Phrase("CarHolder Details", FontFactory.GetFont("verdana", 8));
                PdfPCell cell = new PdfPCell(new Phrase(p1Header));

                table.AddCell(cell);
                ////table.AddCell(cell);
                cell.Colspan = dt.Columns.Count;

                //cell.Border = 0;

                //cell.HorizontalAlignment = 1;
                foreach (DataColumn c in dt.Columns)
                {

                    table.AddCell(new Phrase(c.ColumnName, font5));
                }

                //cell.BackgroundColor = new iTextSharp.text.Color(0xC0, 0xC0, 0xC0);


                foreach (DataRow r in dt.Rows)
                {
                    if (dt.Rows.Count > 0)
                    {
                        table.AddCell(new Phrase(r[0].ToString(), font5));
                        table.AddCell(new Phrase(r[1].ToString(), font5));
                        table.AddCell(new Phrase(r[2].ToString(), font5));
                        table.AddCell(new Phrase(r[3].ToString(), font5));
                        table.AddCell(new Phrase(r[0].ToString(), font5));
                        table.AddCell(new Phrase(r[1].ToString(), font5));
                        table.AddCell(new Phrase(r[2].ToString(), font5));
                        table.AddCell(new Phrase(r[3].ToString(), font5));
                        table.AddCell(new Phrase(r[1].ToString(), font5));
                        table.AddCell(new Phrase(r[2].ToString(), font5));
                        table.AddCell(new Phrase(r[3].ToString(), font5));
                    }


                } document.Add(table);
                //document.Open();
             document.Close();
                retval = "PDF file has been generated your C drive";
            }
            catch (Exception ex)
            {
                retval = ex.Message;
              
            }

            return Json(retval, JsonRequestBehavior.AllowGet);
        }





请帮帮我



谢谢&此致,

soumya



please Help me

Thanks & Regards,
soumya

推荐答案

允许C:驾驶..



检查你是否允许文件夹..



表示读写权限
give permission to C: drive..

Check you given permission to folder..

Means read n write permission


这篇关于pdf文件和excel文件无法创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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