C#文件未转换为PDF

时间:2018-10-08 14:52:31

标签: c# asp.net .net

我正在尝试将文件从Word文档转换为PDF。它在本地工作并保存到文件夹和数据库,但是当我发布它时,出现错误“对象引用未设置为对象的实例”。

string FileExtension = Path.GetExtension(file.FileName);
if (FileExtension == ".doc" || FileExtension == ".docx" || FileExtension == ".rtf" || FileExtension == ".txt")
{
    var fileName = string.Format("{0}_{1}", Guid.NewGuid(), file.FileName);
    file.SaveAs(Server.MapPath("~/TempData/"+file.FileName));
    string FromLocation = Server.MapPath("~/TempData/"+file.FileName);
    string ChangeExtension = fileName.Replace(FileExtension, ".pdf");
    string ToLocation = Server.MapPath("~/PartDocs/"+ChangeExtension);                              
    objWorPdf.InputLocation = FromLocation;
    objWorPdf.OutputLocation = ToLocation;
    objWorPdf.Word2PdfCOnversion();
    model.ShortCut = ChangeExtension;
    if (model.ShortCut == ChangeExtension)
    {

        System.IO.File.Delete(Server.MapPath("~/TempData/" + file.FileName));
    }        
}
model.FileName = file.FileName;

0 个答案:

没有答案