Home  >  Article  >  Backend Development  >  How to download server files to local in asp.net

How to download server files to local in asp.net

高洛峰
高洛峰Original
2017-02-10 17:18:582350browse

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);

How to download server files to local in asp.net

How to download server files to local in asp.net

##The above is given by the editor The method you introduced to download server files to local using asp.net, I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank you all for your support of the PHP Chinese website!

For more asp.net related articles on the method of downloading server files to local, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn