MVC download File mode 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 ();}
MVC download File