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;
        }

posted on 2012-02-20 11:00  多个马甲  阅读(413)  评论(0编辑  收藏  举报