asp to asp.net + binary stream => performace issues

D

David Purton

Hi,

I have some ASP code to stream a binary file. It works well and looks
something like the original ASP code shown below.

I'm experimenting in creating ZIP files on the fly and am trying to come
up with good ways of streaming binary files using ASP.NET, but I'm
having performance issue. The new ASP.NET code is also shown below. The
performance of this is *terrible*. I get less than 200 KB/s across a
LAN. The original code gives a speed the same as just serving a file of
the hard disk directly.

Can anyone give my some pointers to the correct way to do this sort of
thing?

I have experimented using different buffer sizes or writing out the
whole file in one go with no buffer loop, but it does not seem to make a
difference.

I've only just started to experiment with ASP.NET, so I could be trying
to do this completely the wrong way...

The files are about 10MB in size if that matters.

cheers

dc



ORIGINAL ASP CODE:

<%
Function StreamBinaryFile(FileName)
Const adTypeBinary = 1
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
BinaryStream.Type = adTypeBinary
BinaryStream.Open
BinaryStream.LoadFromFile FileName
Do While Not BinaryStream.EOS
Response.BinaryWrite BinaryStream.Read (1048576)
Response.Flush
Loop
Set BinaryStream = Nothing
End Function

Function SaveBinaryFile(FileName, ContentType)
Response.Buffer = True
Response.Clear
Response.AddHeader "Content-Disposition", _
"attachment; filename=" & FileName
set fso = Server.CreateObject ("Scripting.FileSystemObject")
set file = fso.GetFile (Server.MapPath (FileName))
Response.AddHeader "Content-Length", file.Size
Set file = Nothing
Set fso = Nothing
Response.ContentType = ContentType
StreamBinaryFile Server.MapPath (FileName)
Response.End
End Function
%>



NEW ASP.NET CODE:

<script language=C# runat=server>
void StreamBinaryFile (string FileName) {
FileStream BinaryStream = File.OpenRead (FileName);
byte[] buf = new byte[1048576];
while (BinaryStream.Read (buf, 0, 1048576) > 0) {
Response.BinaryWrite (buf);
Response.Flush ();
}
BinaryStream.Close ();
}

void SaveBinaryFile (string FileName, string ContentType) {
FileInfo f = new FileInfo (Server.MapPath (FileName));
Response.BufferOutput = true;
Response.Clear ();
Response.AddHeader ("Content-Disposition",
"attachment; filename=" + FileName);
Response.AddHeader ("Content-Length", f.Length.ToString ());
Response.ContentType = ContentType;
StreamBinaryFile (f.FullName);
Response.End ();
}
</script>
 

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

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,006
Latest member
LauraSkx64

Latest Threads

Top