MVC download File mode
Way One:
Public Filestreamresult Downfile (string filePath, String fileName) {string absolufilepath = Server.MapPath ( system.configuration.configurationmanager.appsettings["AttachmentPath"] + FilePath); Return File (New FileStream (Absolufilepath, FileMode.Open), "Application/octet-stream", Server.URLEncode (FileName)); }
Way two:
Public ActionResult Downfile (string filePath, String fileName) { FilePath = Server.MapPath ( system.configuration.configurationmanager.appsettings["AttachmentPath"] + FilePath); FileStream fs = new FileStream (FilePath, FileMode.Open); byte[] bytes = new byte[(int) fs. Length]; FS. Read (bytes, 0, bytes. Length); FS. Close (); Response.Charset = "UTF-8"; response.contentencoding = System.Text.Encoding.GetEncoding ("UTF-8"); RespOnse. ContentType = "Application/octet-stream";
Response.AddHeader ("Content-disposition", "attachment; Filename= "+ server.urlencode (fileName)); Response.BinaryWrite (bytes); Response.Flush (); Response.End (); return new Emptyresult ();
}
View Call:
<a href="/document/[email protected]&[email protected]"> Download </a>
MVC download File mode