public static bool ConvertPreview(VMCloud.Models.File file, string savePath) { string ext = GetFileExtensioName(file.name); switch (ext) { case "doc": case "docx": Document document = new Document(file.path); document.Save(savePath, Aspose.Words.SaveFormat.Pdf); break; case "pdf": Aspose.Pdf.Document pdf = new Aspose.Pdf.Document(file.path); pdf.Save(savePath, Aspose.Pdf.SaveFormat.Pdf); break; case "ppt": case "pptx": Presentation ppt = new Presentation(file.path); ppt.Save(savePath, Aspose.Slides.Export.SaveFormat.Pdf); break; case "xls": case "xlsx": Workbook book = new Workbook(file.path); book.Save(savePath, Aspose.Cells.SaveFormat.Pdf); break; default: return(false); } return(true); }
public static VMCloud.Models.File UploadFile(HttpPostedFileBase postedFile, string uploaderId, string fileType, string basePath, HttpRequestMessage request) { string uuid = Guid.NewGuid().ToString(); string[] fileNameSlice = postedFile.FileName.Split('.'); string fileExt = fileNameSlice[fileNameSlice.Length - 1]; string previewUuid = Guid.NewGuid().ToString(); VMCloud.Models.File newFile = new VMCloud.Models.File { id = uuid, name = postedFile.FileName, upload_time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), type = fileType, size = HttpUtil.B2KBorMB(postedFile.ContentLength), path = basePath + "\\" + postedFile.FileName + uuid + "." + fileExt, uploader = uploaderId, }; postedFile.SaveAs(newFile.path); try { bool convertOK = HttpUtil.ConvertPreview(newFile, basePath + "\\" + previewUuid + ".pdf"); if (convertOK) { newFile.preview = basePath + "\\" + previewUuid + ".pdf"; } } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, request); } return(newFile); }