ASP.Net 客户端下载文件

 //点击下载链接

 protected void likUrl_Click(object sender, EventArgs e)
        {

    //客户端保存的文件名 
            string fileName = this.hidRCCAUrl.Value.Trim();

    //Config配置的下载路径地址
            string uploadPath = System.Configuration.ConfigurationManager.AppSettings["UploadFiles"];
            string name = uploadPath + "/" + fileName;
            string filePath = Server.MapPath(name);//路径 
            FileInfo fileInfo = new FileInfo(filePath);
            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AddHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8) + "\"");
            Response.AddHeader("Content-Length", fileInfo.Length.ToString());
            Response.AddHeader("Content-Transfer-Encoding", "binary");
            Response.ContentType = "application/octet-stream";
            Response.WriteFile(fileInfo.FullName);
            Response.Flush();
            Response.End();
        }

posted @ 2017-05-15 15:46  萌萌哒Mo  阅读(277)  评论(0编辑  收藏  举报