A. The server sends the corresponding HTTP Response headers information via 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" >
The HTTP-EQUIV representation is the name of the headers, and the content represents the value of the headers
Two. First, to output the MIME type of the file:
Page.Response.AddHeader ("Content-type", "MIME type");
Three. Second, to output the downloaded file's open location and file name:
Page.Response.AddHeader ("Content-disposition", "attachment;filename=" + filename);
The Content-disposition HTTP response header allows you to specify the information that the document represents. With this header, you can specify that the document be opened individually (not in a browser), and can be displayed according to the user's actions. If the user wants to save the document, you can also suggest a file name for the document. This suggestion name appears in the file Name column of the Save as dialog box.
Attachment―― is sent to the client as an attachment, and the client opens the file separately.
Inline―― indicates that the file will be opened in the browser.
Filename―― represents the file name sent to the client file.
Four. Prepare the file data to be sent to the client:
Regardless of the type of file to be converted to a byte-type array first, the byte array is then output to the client using the Response.BinaryWrite method.
String path = "G://download//down.txt";
System.IO.FileInfo file = new System.IO.FileInfo (path);
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);