1、说明
通过文件下载框实现将服务器上的文件下载到本地指定位置。这里需要指定服务器文件路径
代码如下 | 复制代码 |
//服务器文件路径 stringstrFilePath = Server.MapPath("~") +"/excel/20170206104654.xlsx"; FileInfo fileInfo =newFileInfo(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); |