首页 > Web开发 > 详细

ASP.NET下载文件到客户端

时间:2016-01-05 01:35:16      阅读:375      评论:0      收藏:0      [点我收藏+]

2.0下载:


   

        string fileName = "tempimg.jpg";  //下载到客户端后的文件


        string filePath = Server.MapPath("../imgs/img7.jpg"); //要下载的服务器的文件路径


        FileInfo fileInfo = new FileInfo(filePath);  


        Response.Clear();

        Response.ClearContent();

        Response.ClearHeaders();


        Response.Buffer = true;   //设置文档缓存


        Response.AddHeader("Content-Disposition","attachment;filename="+fileName);

        Response.AddHeader("Content-Length",fileInfo.Length.ToString());

        Response.AddHeader("Content-Transfer-Encoding","binary");


        Response.ContentType = "application/octet-stream";

        Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");


        Response.WriteFile(fileInfo.FullName);

        Response.Flush();

        Response.End();



3.5下载:



        

        string fileName = "tempimg.jpg";  //下载到客户端后的文件


        string filePath = Server.MapPath("../imgs/img7.jpg"); //要下载的服务器的文件路径


        Response.Clear();

        Response.Buffer = true;   //设置文档缓存

        Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);


        Response.ContentType = "application/unknown";

        Response.TransmitFile(filePath);

        Response.End();


本文出自 “风中寻觅” 博客,谢绝转载!

ASP.NET下载文件到客户端

原文:http://xingcheng.blog.51cto.com/3693811/1731556

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!