public static Microsoft.AspNetCore.Mvc.FileContentResult ToFileContentResult(this System.Web.Mvc.FileContentResult content) { return(new Microsoft.AspNetCore.Mvc.FileContentResult(content.FileContents, content.ContentType) { FileDownloadName = content.FileDownloadName }); }
public async Task <string> EmailPdfReport(string fileName, string fileContent, string contentType, string applicationPath) { string result = ""; try { await Task.Run(() => { using (SocialCRMEntities db = new SocialCRMEntities()) { List <Attachment> attachmentCollection = new List <Attachment>(); var pdfBinary = Convert.FromBase64String(fileContent.Split(',')[1]); System.Web.Mvc.FileContentResult fileContentResult = new System.Web.Mvc.FileContentResult(pdfBinary, "application/octet-stream"); MemoryStream ms = new MemoryStream(fileContentResult.FileContents); ContentType ct = new ContentType(fileContentResult.ContentType); Attachment attachment = new Attachment(ms, ct); attachment.Name = fileName; attachmentCollection.Add(attachment); List <string> emailIds = db.Emails.Where(x => x.EmailRights.Where(y => y.EmailRightName == "Consolidated").Count() > 0).Select(e => e.EmailId).Distinct().ToList <string>(); EmailSender.SendEmailInThread(emailIds, null, "KE - Automated Communications System Report", "Please find the attached Automated Communications System Report", attachmentCollection); result = "success"; } }); } catch (Exception ex) { throw ex; } return(result); }
public System.Web.Mvc.FileContentResult DownLoadMaterial(int id) { var data = this._ITrainingMaterialRepository.GetSingle(id, base.OrganizationId); var path = HttpRuntime.AppDomainAppPath; string directoryName = System.IO.Path.Combine(path, data.FilePath.Replace("~/", string.Empty)); string mimeType = MimeMapping.GetMimeMapping(data.FileName); var result = new System.Web.Mvc.FileContentResult(System.IO.File.ReadAllBytes(directoryName), mimeType) { FileDownloadName = data.FileName }; return(result); }
/// <summary> /// 获取图形验证码 /// </summary> /// <returns></returns> public JsonResult <Result <dynamic> > GetImageCheckCode() { string code; var image = Core.Helper.ImageHelper.GenerateCheckCode(out code); var id = Guid.NewGuid().ToString("N"); Cache.Insert("ImageCheckCode:" + id, code, 600); var file = new System.Web.Mvc.FileContentResult(image.ToArray(), "image/png"); return(JsonResult <dynamic>(new { Id = id, file.ContentType, file.FileContents, file.FileDownloadName })); }
public static System.Web.Mvc.FileContentResult GetDirectoryImages(string root) { string folder = IOHelper.GetDiskLocation(root); IOHelper.CheckAndCreateFolder(folder); Ionic.Zip.ZipFile fileZip = new ZipFile(); string[] directorios = Directory.GetDirectories(folder); MemoryStream output = new MemoryStream(); fileZip.AddDirectory(folder); var miniaturas = fileZip.Entries.Where(m => m.FileName.Contains(ConfigurationHelper.ImagenMiniatura)).ToList(); foreach (var item in miniaturas) { fileZip.RemoveEntry(item.FileName); } fileZip.Save(output); var result = new System.Web.Mvc.FileContentResult(output.ToArray(), "application/octet-stream"); result.FileDownloadName = "IBVD_Imagenes.zip"; return(result); }