473,408 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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

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>
Jan 27 '06 #1
0 1144

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Eric | last post by:
Assume that disk space is not an issue (the files will be small < 5k in general for the purpose of storing preferences) Assume that transportation to another OS may never occur. Are there...
103
by: Steven T. Hatton | last post by:
§27.4.2.1.4 Type ios_base::openmode Says this about the std::ios::binary openmode flag: *binary*: perform input and output in binary mode (as opposed to text mode) And that is basically _all_ it...
8
by: Yeow | last post by:
hello, i was trying to use the fread function on SunOS and ran into some trouble. i made a simple test as follows: i'm trying to read in a binary file (generated from a fortran code) that...
2
by: dansan | last post by:
I have been tryning to make some of our C# programs talk to some perl programs. These perl jewels output in binary. I have been trying to use Process.StandardOutput to read the output from the...
2
by: gauravkhanna | last post by:
Hi All I need some help for the below problem: Scenario We need to send large binary files (audio file of about 10 MB or so) from the client machine (.Net Windows based application, located...
6
by: | last post by:
Hi all, is there a better way to stream binary data stored in a table in sql 2005 to a browser in .net 2.0? Or is the code same as in .net 1.1? We noticed that in certain heavy load scenarios,...
2
by: Wayne Marsh | last post by:
Hello, Is it considered sane/good practice to write a global operator for the insertion and extraction operators of an fstream in binary mode to serialize a binary class, or are they strictly...
1
by: Michael | last post by:
I have a solution for this, but it feels wrong. If anyone could offer a better one, I'm all ears. (Or technically, eyes.) Basically, I have a bunch of classes. For concreteness, one is a...
0
by: Michael B. Trausch | last post by:
I am attempting to piece together a Python client for Fotobilder, the picture management server on Livejournal. The protocol calls for binary data to be transmitted, and I cannot seem to be able...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.