private void btnDownload_Click(object sender, System.EventArgs e)
{
string filepath = @"C:\shadow_copy.rar";
string filename = Path.GetFileName( filepath );
System.IO.Stream stream = null;
try
{
stream = new FileStream( filepath, System.IO.FileMode.Open,System.IO.FileAccess.Read, System.IO.FileShare.Read );
long bytesToRead = stream.Length;
Response.ContentType = "application/octet-stream";
Response.AddHeader( "Content-Disposition", "attachment; filename=" + filename );
while ( bytesToRead > 0 )
{
if ( Response.IsClientConnected )
{
byte[] buffer = new Byte[10000];
int length = stream.Read( buffer, 0, 10000 );
Response.OutputStream.Write(buffer, 0, length);
Response.Flush();
bytesToRead = bytesToRead - length;
}
else
{
bytesToRead = -1;
}
}
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
finally
{
if ( stream != null ) {
stream.Close();
}
}
}