A retriable solution that uses binary stream downloads is like a http://www.abc.com/down.apsx? For a connection such as fileid = 911199, the permission is determined on the down page, for example, whether the user has logged on, and whether the number of current user points meets the number of download points of the corresponding file of 911199.
Binary Download instance code, supporting extra-large file downloads
String downFilePath = @ "D: \ openSUSE-10.2-GM-DVD-i386.iso"; // test with 3.8 GB, OK // Server. MapPath ("~ /Files/somefile. iso ");
System. IO. FileInfo downFileInfo = new System. IO. FileInfo (downFilePath );
If (! DownFileInfo. Exists) throw new Exception ("the file does not exist. ");
Const int CHUNK_SIZE = 10000; // specify the block size
Byte [] buffer = new byte [CHUNK_SIZE];
Response. Clear ();
// Fails to down the big file with both the following methods
// Error: System. ArgumentOutOfRangeException: The size parameter must be between zero and the maximum Int32 value.
// Response. WriteFile (downFilePath );
// OR
// Response. TransmitFile (downFilePath); // ASP. NET 2.0 supported
//
Using (System. IO. FileStream iStream = System. IO. File. OpenRead (downFilePath )){
Long dataLengthToRead = iStream. Length;
Response. ContentType = "application/octet-stream ";
Response. AddHeader ("Content-Disposition ",
"Attachment; filename =" + Server. UrlPathEncode (downFileInfo. Name); // encode the file Name
While (dataLengthToRead> 0 & Response. IsClientConnected ){
Int lengthRead = iStream. Read (buffer, 0, CHUNK_SIZE );
Response. OutputStream. Write (buffer, 0, lengthRead );
Response. Flush ();
DataLengthToRead = dataLengthToRead-lengthRead;
}
}
Response. Close ();
Author Zheng wenliang