This article mainly introduces the method of asp.net to download server files to local. Friends who need it can refer to
1. Instructions
Use the file download box to realize downloading files on the server Download the file to the local specified location. Here you need to specify the server file path
//服务器文件路径 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);