System.IO.Stream iStream = null;
byte[] buffer = new Byte[10000];
int length;
long dataToRead;
string filename = System.IO.Path.GetFileName(fileSpec);
try
{
iStream = new System.IO.FileStream(fileSpec, System.IO.FileMode.Open,System.IO.FileAccess.Read,System.IO.FileShare.Read);
dataToRead = iStream.Length;
Response.ContentType = GetContentType(fileSpec);
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
while (dataToRead > 0)
{
if (Response.IsClientConnected)
{
length = iStream.Read(buffer, 0, 10000);
Response.OutputStream.Write(buffer, 0, length);
Response.Flush();
buffer= new Byte[10000];
dataToRead = dataToRead - length;
}
else
{
dataToRead = -1;
}
}
}
catch (Exception ex)
{
Response.Write("Error : " + ex.Message);
}
finally
{
if (iStream != null)
{
iStream.Close();
}
}
byte[] buffer = new Byte[10000];
int length;
long dataToRead;
string filename = System.IO.Path.GetFileName(fileSpec);
try
{
iStream = new System.IO.FileStream(fileSpec, System.IO.FileMode.Open,System.IO.FileAccess.Read,System.IO.FileShare.Read);
dataToRead = iStream.Length;
Response.ContentType = GetContentType(fileSpec);
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
while (dataToRead > 0)
{
if (Response.IsClientConnected)
{
length = iStream.Read(buffer, 0, 10000);
Response.OutputStream.Write(buffer, 0, length);
Response.Flush();
buffer= new Byte[10000];
dataToRead = dataToRead - length;
}
else
{
dataToRead = -1;
}
}
}
catch (Exception ex)
{
Response.Write("Error : " + ex.Message);
}
finally
{
if (iStream != null)
{
iStream.Close();
}
}