首页 > 技术文章 > 文件下载

wzq806341010 2013-09-30 09:11 原文

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

 

推荐阅读