Way One:
Public Filestreamresult downfile (stringstring fileName) { string Absolufilepath = Server.MapPath (system.configuration.configurationmanager.appsettings[" AttachmentPath"] + filePath); return File (new"application/octet-stream", Server.URLEncode (fileName) ); }
Way two:
PublicActionResult Downfile (stringFilePath,stringfileName) {FilePath= Server.MapPath (system.configuration.configurationmanager.appsettings["AttachmentPath"] +FilePath); FileStream FS=NewFileStream (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 NewEmptyresult (); }
MVC download File mode