public IHttpActionResult RemoveFileAttachment(RemoveAttachmentModel removeAttachmentModel) { var httpRequest = HttpContext.Current.Request; var fullPath = Path.Combine(Config.Configuration.WorkingDirectory.Replace("/", "\\"), "Editor", removeAttachmentModel.documentId); var pdfDocumentPath = string.Format("{0}\\document.pdf", fullPath); // Open document try { using (Document pdfDocument = new Document(pdfDocumentPath)) { EmbeddedFileCollection embeddedFiles = pdfDocument.EmbeddedFiles; pdfDocument.EmbeddedFiles.Delete(removeAttachmentModel.attachmentFileName); } var model = new FileAttachmentsModel { d = "Success", Path = HttpContext.Current.Request.Form["documentId"] }; return(Ok(model)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult GetFileAttachments(string folder) { var fullPath = Path.Combine(Config.Configuration.WorkingDirectory.Replace("/", "\\"), "Editor", folder); var pdfDocumentPath = string.Format("{0}\\document.pdf", fullPath); string outAttach = ""; // Open document using (Document pdfDocument = new Document(pdfDocumentPath)) { // Get embedded files collection EmbeddedFileCollection embeddedFiles = pdfDocument.EmbeddedFiles; // Loop through the collection to get all the attachments foreach (FileSpecification fileSpecification in embeddedFiles) { outAttach = outAttach + "," + fileSpecification.Name + "," + fileSpecification.Description; } if (outAttach.Length > 1) { outAttach = outAttach.Substring(1); } } var model = new FileAttachmentsModel { d = outAttach }; return(Ok(model)); }