1. The server outputs the corresponding HTTP Response Headers information through response and the data of the file to be downloaded to send the file to the client. The HTTP Response Headers is shown in the following form in the HTML file:
<Meta http-equiv = "Content-Type" content = "text/htm">
HTTP-equiv indicates the headers name, and content indicates the value of this headers.
2. First, the MIME type of the file to be output:
Page. response. addheader ("Content-Type", "MIME type ");
3. Second, output the Open Location and file name of the downloaded file:
Page. response. addheader ("content-disposition", "attachment; filename =" + filename );
The HTTP Response Header of content-Disposition allows you to specify the information displayed in the document. With this header, you can specify the document to be opened separately (instead of in the browser) and display it according to user operations. If you want to save a document, you can also recommend a file name for this document. The recommended name will appear in the "file name" column of the Save As dialog box.
Attachment-the attachment is sent to the client, and the client opens the file separately.
Inline-indicates that the file will be opened in the browser.
Filename-indicates the file name sent to the client.
4. file data to be sent to the client:
No matter what type of file, convert it to an array of the byte type, and then output the byte array to the client using the response. binarywrite method.
String Path = "G: \ Download \ down.txt ";
System. Io. fileinfo file = new system. Io. fileinfo (PATH );
Response. Clear ();
Response. addheader ("content-disposition", "attachment; filename =" + httputility. urlencode (file. Name ));
Response. addheader ("Content-Length", file. length. tostring ());
Response. contenttype = "application/octet-stream ";
Response. writefile (file. fullname );
Response. End ();