ASP.NET File Download messed up

Discussion in 'ASP .Net' started by joshua_jacobsen@oxy.com, Apr 19, 2007.

  1. Guest

    I have a problem with file downloads. Here is the basic code:

    sqlstring = "SELECT * FROM [File_Store] WHERE RecordID = " &
    formatDBNumber(RecordID) & ";"
    SQLDataSetObject = New DataSet("Image")
    SQLAdapterObject = New SqlDataAdapter(sqlstring,
    SQLConnectionObject)
    SQLCommandBuilderObject = New
    SqlCommandBuilder(SQLAdapterObject)
    SQLAdapterObject.Fill(SQLDataSetObject, "Table")

    Try
    File_Name = SQLDataSetObject.Tables("Table").Rows(0)
    ("File_Name")
    File_Size = SQLDataSetObject.Tables("Table").Rows(0)
    ("File_Size")
    File_MimeType = SQLDataSetObject.Tables("Table").Rows(0)
    ("File_MimeType")
    Dim File_Binary(File_Size) As Byte
    File_Binary = SQLDataSetObject.Tables("Table").Rows(0)
    ("File_Binary")

    response.Clear()
    response.ContentType = File_MimeType
    response.OutputStream.Write(File_Binary, 0,
    File_Binary.Length)
    response.End()
    Catch ex As Exception
    response.Write(ex.Message)
    End Try

    This works when I have certain types of files in the database (like
    PDF files). However, if the mime type is "application/vnd.ms-excel"
    for an XLS file, or a word doc, the file comes out as garbage in the
    browser window instead of being recognized as a document of the
    appropriate mime type.

    Using a packet sniffer, I discovered that ASP.NET is inexplicable
    appending a ton of spaces and "; charset=utf-8" at the end of my mime
    type. I can verify that this text is not in my variable
    (File_MimeType) above, nor in the database field where that variable
    is read from.

    I believe that this insertion is screwing up my file transfer.

    The aspx file has no HTML in it at all, but has a reference to the
    code file
    "<%@ Page Language="vb" AutoEventWireup="false"
    Codebehind="File.aspx.vb" Inherits="FPA_AFE.File" %>"

    There are no other response commands in my code anywhere. The IIS
    server is set to enable buffering.
    , Apr 19, 2007
    #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. Ravikanth[MVP]

    why my aspx page is messed up by VS?

    Ravikanth[MVP], Aug 5, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    277
    Ravikanth[MVP]
    Aug 5, 2003
  2. Berrucho

    Session ID's messed up?

    Berrucho, Nov 13, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    310
    Berrucho
    Nov 13, 2003
  3. Steve C. Orr [MVP, MCSD]
    Replies:
    0
    Views:
    1,588
    Steve C. Orr [MVP, MCSD]
    Mar 7, 2005
  4. Jensen bredal
    Replies:
    4
    Views:
    628
    Jensen bredal
    Mar 21, 2005
  5. xMANIGHTx
    Replies:
    2
    Views:
    139
    xMANIGHTx
    Sep 15, 2004
Loading...

Share This Page