Dears
i developed a web application in mvc technology and angular js.
my client upload attachments in the following extensions (pdf,.jpeg,xlsx,doc).
he wants attachments details page when click on preview button these files show on popup without download it
it works smoothly with images and PDF
but i developed a method to convert (doc and excel ) to PDF .
it works on local but when i published my site on test server (windows server 2008 r2 )
it doesn't work and return null reference e exception
can you check my code
public JsonResult Convertfiletopdf(string filename, string filePatgh) { try { //ExcelFile.Load("Workbook.xlsx").Save("Workbook.pdf"); filePatgh = Path.Combine(Server.MapPath("~/Uploads/")); if (filename.Contains(".xlsx")) { var newfilename = filename.Replace(".xlsx", ".pdf"); var app = new Application(); var wkb = app.Workbooks.Open(filePatgh + filename); if (!System.IO.File.Exists(filePatgh + newfilename)) { //wkb.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, filePatgh + newfilename); wkb.ExportAsFixedFormat( XlFixedFormatType.xlTypePDF, filePatgh + newfilename, XlFixedFormatQuality.xlQualityStandard, true, true, 1, 10, false); } wkb.Close(); } if (filename.Contains(".xls")) { var newfilename = filename.Replace(".xls", ".pdf"); var app = new Application(); var wkb = app.Workbooks.Open(filePatgh + filename); if (!System.IO.File.Exists(filePatgh + newfilename)) { wkb.ExportAsFixedFormat( XlFixedFormatType.xlTypePDF, filePatgh + newfilename, XlFixedFormatQuality.xlQualityStandard, true, true, 1, 10, false); // wkb.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, filePatgh + newfilename); } wkb.Close(); } else { var objWorPdf = new Word2Pdf(); var fromLocation = filePatgh + "\\" + filename; var fileExtension = Path.GetExtension(filename); var changeExtension = filename.Replace(fileExtension, ".pdf"); object toLocation = filePatgh + "\\" + changeExtension; objWorPdf.InputLocation = fromLocation; objWorPdf.OutputLocation = toLocation; if (!System.IO.File.Exists(filePatgh + changeExtension)) { objWorPdf.Word2PdfCOnversion(); } } return Json(filename, JsonRequestBehavior.AllowGet); } catch (Exception ex) { throw ; } }
Dears your help is highly appreciated here .
Thanks all