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.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 8);
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);
cell.Colspan = dt.Columns.Count;
foreach (DataColumn c in dt.Columns)
{
table.AddCell(new Phrase(c.ColumnName, font5));
}
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.Close();
retval = "PDF file has been generated your C drive";
}
catch (Exception ex)
{
retval = ex.Message;
}
return Json(retval, JsonRequestBehavior.AllowGet);
}
please Help me
Thanks & Regards,
soumya