文件下载

   public ActionResult DownAttachment(string dUrl, string fileName)
        {
            try
            {
                dUrl = HttpUtility.UrlDecode(dUrl);
                var bytes = new System.Net.WebClient().DownloadData(dUrl);
                Response.ContentType = "application/octet-stream";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
                Response.BinaryWrite(bytes);
                Response.Flush();
                Response.End();
            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('下载失败!远程服务器异常!');</script>");
            }
            return new EmptyResult();
        }

 

posted on 2013-09-30 09:11  朝着  阅读(123)  评论(0编辑  收藏  举报