First of all, share some exciting news:
1. Google has announced its accession. NET Foundation
2. Microsoft joined the Linux Foundation and continued to be good with Linux. The CEO is different.
3. Microsoft Release vs for mac!
First Step Download DLL
Install the following DLL in the NuGet.
Step Two Download method
Project structure
Add the following method to our general handler
///<summary>///bulk pack download Author: Wu Di///</summary>///<param name= "FileName" > file name </param>///<param name= "FilePath" > File virtual path </param> public static void Downloadfil Es (String fileName, String filePath) {list<string> fileNames = filename.split (' | ').
ToList (); list<string> filepaths = filepath.split (' | ').
ToList ();
MemoryStream ms = new MemoryStream ();
byte[] buffer = NULL; using (ZipFile file = Zipfile.create (ms)) {file.
BeginUpdate (); File.
Nametransform = new Mynametransfom (); Filepaths.foreach (t => {file.
ADD (HttpContext.Current.Server.MapPath (t));
});
File.commitupdate (); Buffer = new Byte[ms.
Length]; Ms.
Position = 0; Ms. Read (buffer, 0, buffer.)
Length);
string ss = "Bulk Download" + filenames[0] + "et";
HttpContext.Current.Response.AddHeader ("Content-disposition", "attachment;filename=" + SS + ". zip"); HttpContext.Current.ResponsE.binarywrite (buffer);
HttpContext.Current.Response.Flush ();
HttpContext.Current.Response.End (); }
The third step calls the method
Try downloading the files in our pic directory!
public void ProcessRequest (HttpContext context)
{
//context. Response.ContentType = "Text/plain";
Context. Response.Write ("Hello World");
Downloadfiles ("xxx", "~/pic/00.gif|~/pic/02.png");
}
Step Fourth Test results
Run the project!
Here is the package result:
The final discussion of the fifth step
I've seen a lot of friends and co-workers who don't understand how to download files directly to the browser.
In fact, my last remark was wrong. The file is not downloaded to the browser, but along with the HTTP request, you request a series of information such as parameters to flow to the downstream server. And your HTTP server, after receiving the request, after processing, and then to the downstream client, return a series of response results.
All you have to do is read your file into the response stream, and when the browser gets your head notice, it will naturally be downloaded to you as a file.
All your transmissions are due to the HTTP protocol, which is based on the TCP/IP protocol family, and in the HTTP application layer, you make a great contribution to the transport layer, the network layer, and the data link layer. In the transport layer, there is TCP to provide you with secure and reliable transmission support, and all network traffic requires almost all network layer IP protocol, and finally to the data Link layer a series of your visible routing devices.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.