首页 > Web开发 > 详细

asp.net实现服务器文件下载到本地

时间:2017-02-06 12:53:41      阅读:151      评论:0      收藏:0      [点我收藏+]

1、说明

  通过文件下载框实现将服务器上的文件下载到本地指定位置。这里需要指定服务器文件路径

    //服务器文件路径
    string strFilePath = Server.MapPath("~") + "/excel/20170206104654.xlsx";

    FileInfo fileInfo = new FileInfo(strFilePath);
    Response.Clear();
    Response.AddHeader("content-disposition", "attachment;filename=" + Server.UrlEncode(fileInfo.Name.ToString()));
    Response.AddHeader("content-length", fileInfo.Length.ToString());
    Response.ContentType = "application/octet-stream";
    Response.ContentEncoding = System.Text.Encoding.Default;
    Response.WriteFile(strFilePath);

技术分享

 技术分享

asp.net实现服务器文件下载到本地

原文:http://www.cnblogs.com/lengzhan/p/6369500.html

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