asp.net mvc 下载文件
[Authorize]
public FileContentResult DwonAttachment(int id) // controller - action
{
Member_Attachment ma = new Member_Attachment(); // class
TMember_Attachment model = ma.GetModel(id);
if (model != null)
{
try
{
int memberid = model.MemberID;
if (System.IO.File.Exists(model.NewFilePath)) -- file exists
{
byte[] bts = System.IO.File.ReadAllBytes(model.NewFilePath);
// model.MimeType == fileType (.jpg.txt)
return File(bts, model.MimeType, model.OldFileName);
}
}
catch { }
}
return null;
}