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

Discussion in 'ASP .Net' started by David Purton, Jan 27, 2006.

  1. David Purton

    David Purton Guest

    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>
     
    David Purton, Jan 27, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. thisyr4leafs

    ASP.NET Page Performace Problem

    thisyr4leafs, Aug 26, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,091
    John Rivers
    Aug 27, 2005
  2. Stephan Br?nnimann
    Replies:
    2
    Views:
    303
    P.J. Plauger
    Nov 10, 2003
  3. Lucky
    Replies:
    1
    Views:
    813
    Matt Humphrey
    Jun 1, 2006
  4. TPJ
    Replies:
    3
    Views:
    282
    Justin Azoff
    Aug 7, 2005
  5. Steven T. Hatton
    Replies:
    3
    Views:
    326
    Victor Bazarov
    Jun 28, 2005
Loading...

Share This Page