public async Task <IActionResult> EditResume(CareerModel career, IFormFile file, [FromServices] IHostingEnvironment hostingEnvironment) { // string filePath = $"{_hostingEnvironment.WebRootPath}\\files\\{file.FileName}"; if (file != null && file.Length > 0) { string filePath = $"{_hostingEnvironment.WebRootPath}\\files\\{file.FileName}"; string fileName = file.FileName; if (fileName.Split(".").Last() == "pdf") { using (FileStream fileStream = System.IO.File.Create(filePath)) { file.CopyTo(fileStream); career.Resume = fileName; fileStream.Flush(); fileStream.Close(); } } else { string extentionFile = file.FileName.Split(".").Last(); int indexextensionFile = file.FileName.LastIndexOf(extentionFile); fileName = file.FileName.Substring(0, indexextensionFile); fileName = fileName + "pdf"; filePath = $"{_hostingEnvironment.WebRootPath}\\files\\{fileName}"; using (FileStream fileStream = System.IO.File.Create(filePath)) { file.CopyTo(fileStream); career.Resume = fileName; fileStream.Flush(); fileStream.Close(); } if (file.FileName.Split(".").Last() == "docx" || file.FileName.Split(".").Last() == "doc" || file.FileName.Split(".").Last() == "docm" || file.FileName.Split(".").Last() == "dot" || file.FileName.Split(".").Last() == "dotx") { Document document = new Document(); document.LoadFromFile(filePath); document.SaveToFile(filePath, Spire.Doc.FileFormat.PDF); } else if (file.FileName.Split(".").Last() == "ppt" || file.FileName.Split(".").Last() == "pptx" || file.FileName.Split(".").Last() == "pptm") { Presentation presentation = new Presentation(); presentation.LoadFromFile(filePath); presentation.SaveToFile(filePath, Spire.Presentation.FileFormat.PDF); } else { Workbook workbook = new Workbook(); workbook.LoadFromFile(filePath); Worksheet sheet = workbook.Worksheets[0]; sheet.SaveToPdf(filePath); } } } var edit_carrer = await services.EditResume(career); if (edit_carrer != null) { return(RedirectToAction("index", "Career")); } return(View()); }