I have an MVC5 C# project and in one of the pages, i'm showing a list of HTML email templates so the user can see how the email templates are and be aware of what is being send to the customers. Now, what i want is a button in each template that allow me to download that template in one .html
file. How is this possible?
Use
public ActionResult Index()
{
var fc = System.IO.File.ReadAllBytes(Server.MapPath("~/Path/To/File.html");
return File(fc, "application/octet-stream", "download file name.html");
}
This will change the way the client will process it and will assume it's a downloadable file.
Tested on IE11 and FF.
Finally i came with this solution:
public ActionResult DownloadTemplate(string templateName)
{
using (var service = new MyService())
{
var template = service.GetEmailTemplateByName(templateName);
string attachment = string.Format("attachment; filename={0}_TEMPLATE.html", templateName);
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "text/html";
Response.Write(template.Body);
Response.End();
return new EmptyResult();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.