public IActionResult OnPost(AddCaseModel model) { try { if (model.IsValid()) { var fileUpload = Path.Combine(ihostingEnvironment.ContentRootPath, "Files", AttachmentUploader.FileName); FileInfo fi = new FileInfo(fileUpload); var extension = fi.Extension; var stream = new MemoryStream(); var img = AttachmentUploader.CopyToAsync(stream); var fileBytes = stream.ToArray(); string base64 = Convert.ToBase64String(fileBytes); model.CaseAttachment = base64; model.AttachmentExtension = extension; var res = addCaseCommand.Execute(model); } return(RedirectToPage("/AddNewCase")); } catch (Exception ex) { ErrorHandling errorHandling = new ErrorHandling(); var res = errorHandling.GetErrorMessage(ex); TempData["ErrorMessage"] = res; return(null); } }
/// <summary> /// Uploads attachments to a page. /// </summary> /// <param name="pageFullName">The full name of the wiki page.</param> public bool AttachFiles(String pageFullName) { string[] fileNames = SelectLocalFiles(); addin.Application.StatusBar = "Adding " + fileNames.Length + " attachments to " + pageFullName + " ..."; AttachmentUploader attachmentUploader = new AttachmentUploader(addin, pageFullName, Client, fileNames); attachmentUploader.Perform(); bool attached = attachmentUploader.GetResults(); if (attached) { addin.Application.StatusBar = "Attachments uploaded!"; } else { addin.Application.StatusBar = "Error uploading attachments!"; UserNotifier.Error(UIMessages.ERROR_UPLOADING_ATTACHMENTS); } return(attached); }
/// <summary> /// Uploads attachments to a page. /// </summary> /// <param name="pageFullName">The full name of the wiki page.</param> public bool AttachFiles(String pageFullName) { string[] fileNames = SelectLocalFiles(); addin.Application.StatusBar = "Adding " + fileNames.Length + " attachments to " + pageFullName + " ..."; AttachmentUploader attachmentUploader = new AttachmentUploader(addin, pageFullName, Client, fileNames); attachmentUploader.Perform(); bool attached = attachmentUploader.GetResults(); if (attached) { addin.Application.StatusBar = "Attachments uploaded!"; } else { addin.Application.StatusBar = "Error uploading attachments!"; UserNotifier.Error(UIMessages.ERROR_UPLOADING_ATTACHMENTS); } return attached; }