CopyCode The Code is as follows: public void filedownloaddel (string fullfilename)
{
System. Io. Stream istream = NULL;
// Buffer to read 10 K bytes in Chunk:
Byte [] buffer = new byte [10000];
// Length of the file:
Int length;
// Total Bytes to read:
Long datatoread;
// Identify the file to download including its path.
String filepath = fullfilename;
Filepath = server. mappath (filepath );
// Identify the file name.
String filename = system. Io. Path. getfilename (filepath );
Try
{
// Open the file.
Istream = new system. Io. filestream (filepath, system. Io. filemode. Open,
System. Io. fileaccess. Read, system. Io. fileshare. Read );
// Total Bytes to read:
Datatoread = istream. length;
Response. contenttype = "application/octet-stream ";
Response. addheader ("content-disposition", "attachment; filename =" + filename );
// Read the bytes.
While (datatoread> 0)
{
// Verify that the client is connected.
If (response. isclientconnected)
{
// Read the data in buffer.
Length = istream. Read (buffer, 0, 10000 );
// Write the data to the current output stream.
Response. outputstream. Write (buffer, 0, length );
// Flush the data to the HTML output.
Response. Flush ();
Buffer = new byte [10000];
Datatoread = datatoread-length;
}
Else
{
// Prevent infinite loop if user disconnects
Datatoread =-1;
Response. Clear ();
}
}
Response. End (); // The content refreshed on the page is appended to the file.
}
Catch (exception ex)
{
// Trap the error, if any.
// Response. Write ("error:" + ex. Message );
// Base. writelog ("", ":" + ex. Message + "! ", Logtype. error, this. GetType (). tostring ());
}
Finally
{
If (istream! = NULL)
{
// Close the file.
Istream. Close ();
}
File. Delete (fullfilename );
}
}