1. transmitfile to solve the problem that the aspnet_wp.exe process cannot be successfully downloaded when response. binarywrite downloads a file larger than MB.
String filename = "Planning Information Data Warehouse field description .doc"; // file name saved by the client
Response. contenttype = "application/X-zip-compressed ";
Response. addheader ("content-disposition", "attachment; filename =" + httputility. urlencode (filename, system. Text. encoding. utf8 ));
String filename = server. mappath ("download/Planning Information Data Warehouse field description .doc ");
Response. transmitfile (filename );
2. Download in the form of a stream
String filename = "Planning Information Data Warehouse field description .doc"; // file name saved by the client
String filepath = server. mappath ("download/Planning Information Data Warehouse field description .doc"); // path
// Download an object in the form of a streaming
Filestream FS = new filestream (filepath, filemode. Open );
Byte [] bytes = new byte [(INT) fs. Length];
FS. Read (bytes, 0, bytes. Length); // read to the specified array
FS. Close ();
Response. contenttype = "application/octet-stream ";
// Notify the browser to download the file instead of opening it
Response. addheader ("content-disposition", "attachment; filename =" + httputility. urlencode (filename, system. Text. encoding. utf8 ));
Response. binarywrite (bytes );
Response. Flush ();
Response. End ();