We have some files stored in sql database. On an ASP.NET MVC3 form, we display 2 links:
View this file | Download this file
These links go to these correspon
When you use the overload File(byte[] contents, string mimeType, string fileName)
a Content-Disposition
header is automatically added to the response with attachment
, so you don't need to add it a second time. For inline
you could use the following overload File(byte[] contents, string mimeType)
and manually add the Content-Disposition
header:
[ActionName("display-file")]
public virtual ActionResult DisplayFile(Guid fileId)
{
var file = _repos.GetFileInfo(fileId);
var cd = new ContentDisposition
{
Inline = true,
FileName = file.Name
};
Response.AddHeader("Content-Disposition", cd.ToString());
return File(file.Content, file.MimeType);
}
[ActionName("download-file")]
public virtual ActionResult DownloadFile(Guid fileId)
{
var file = _repos.GetFileInfo(fileId);
return File(file.Content, file.MimeType, file.Name);
}