This article mainly introduces the ASP. NET use General processing program to achieve file download function, very good, with reference value, the need for friends can refer to the next
First there is an HTML page, the page has a link, click the link pop-up file download/save (similar to Thunder download link)
<! DOCTYPE html>
The code for the generic handler is as follows
Using system.io;using system.web;namespace zhong.web{//<summary>//Downloadfilehandler Summary description///</summary > public class Downloadfilehandler:ihttphandler {public void ProcessRequest (HttpContext context) {string Filepa th = context. Server.MapPath ("~/app_data/readme.txt"); FileStream fs = new FileStream (FilePath, FileMode.Open); byte[] bytes = new Byte[fs. Length]; Fs. Read (bytes, 0, bytes. Length); Fs. Dispose (); Context. Response.ContentType = "Application/octet-stream"; Context. Response.AddHeader ("Content-disposition", "attachment; Filename=readme.txt "); Context. Response.BinaryWrite (bytes); Context. Response.Flush (); Solution for large file download//context. Response.ContentType = "application/x-zip-compressed"; Context. Response.AddHeader ("Content-disposition", "Attachment;filename=z.zip"); string filename = Server.MapPath ("~/app_data/move.zip"); Context. Response.TransmitFile (filename); } public bool IsReusable {get {return false; } } }}
Click on the first link to access it as shown below:
Click the second link to access and download the file:
Since I have already tested it before, this download is named Readme (1). txt