Re: Problem with Response.TransmitFile

  • Thread starter Daniel Fisher\(lennybacon\)
  • Start date
D

Daniel Fisher\(lennybacon\)

You should not use the built in method for such big downloads. Use

Context.Response.Buffer=false;
FileStream inStr = null;
byte[] buffer = new byte[1024];
long byteCount;

inStr = File.OpenRead(filePath);
while ((byteCount = inStr.Read(buffer, 0, buffer.Length)) > 0)
{
if(Context.Response.IsClientConnected)
{
Context.Response.OutputStream.Write(buffer, 0, buffer.Length);
Context.Response.Flush();
}
}

instead and sent the file bitwise.

--Daniel Fisher(lennybacon)
 
G

Guest

Hi,

Thank you very much for the suggestion!
Do you have the code in VB format, my project is programmed in Vb…

Thanks again,
Thomas Andersson


Daniel Fisher(lennybacon) said:
You should not use the built in method for such big downloads. Use

Context.Response.Buffer=false;
FileStream inStr = null;
byte[] buffer = new byte[1024];
long byteCount;

inStr = File.OpenRead(filePath);
while ((byteCount = inStr.Read(buffer, 0, buffer.Length)) > 0)
{
if(Context.Response.IsClientConnected)
{
Context.Response.OutputStream.Write(buffer, 0, buffer.Length);
Context.Response.Flush();
}
}

instead and sent the file bitwise.

--Daniel Fisher(lennybacon)


Thomas Andersson said:
Hi,

I have a problem with Response.TransmitFile.
The server reset the connection after approx. 20 minutes and sometimes
after
7-8 minutes when i try to download large files (400MB +) with
Response.TransmitFile.

What can be the problem?

I have tried to use httpRuntime executionTimeout="14400"
maxRequestLength="1048576".

Any ideas?
 
G

Guest

Hi,

Thank you very much for the suggestion!
Do you have the code in VB format, my project is programmed in Vb…

I have tryed to use the code below, but it wont work...

Dim AbsFilePath As String
AbsFilePath = Server.MapPath(FilePath)
Response.Buffer = False
Server.ScriptTimeout = 30000
Page.Response.ClearHeaders()
'Set the content type
Response.ContentType = "application/pdf"
Response.AddHeader("Content-Disposition", "attachment; filename=" & FileName)

Dim DownloadStream As FileStream
Dim Buffer(1024) As Byte
Dim ByteCount As Long
DownloadStream = File.OpenRead(AbsFilePath)
Dim FileSize = DownloadStream.Length
Response.AddHeader("Content-Length", FileSize)

While ((ByteCount = DownloadStream.Read(Buffer, 0, Buffer.Length)) > 0)
If (Context.Response.IsClientConnected) Then
Context.Response.OutputStream.Write(Buffer, 0, Buffer.Length)
Context.Response.Flush()
End If
End While

DownloadStream.Close()
Response.End()

I also have two other problems...

1. I use Response.ContentType = "application/pdf", but if the filename is
test.txt the download window shows that it is a text file.
How can I force it to show pdf instead?

2. If I download a file with the name Test_1.1.1.txt, Internet Explorer
renames it to
Test_1[1].1.1.txt.
How can I force it to keep the name Test_1.1.1.txt?


Daniel Fisher(lennybacon) said:
You should not use the built in method for such big downloads. Use

Context.Response.Buffer=false;
FileStream inStr = null;
byte[] buffer = new byte[1024];
long byteCount;

inStr = File.OpenRead(filePath);
while ((byteCount = inStr.Read(buffer, 0, buffer.Length)) > 0)
{
if(Context.Response.IsClientConnected)
{
Context.Response.OutputStream.Write(buffer, 0, buffer.Length);
Context.Response.Flush();
}
}

instead and sent the file bitwise.

--Daniel Fisher(lennybacon)


Thomas Andersson said:
Hi,

I have a problem with Response.TransmitFile.
The server reset the connection after approx. 20 minutes and sometimes
after
7-8 minutes when i try to download large files (400MB +) with
Response.TransmitFile.

What can be the problem?

I have tried to use httpRuntime executionTimeout="14400"
maxRequestLength="1048576".

Any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top