ASP.NET File Download messed up

J

joshua_jacobsen

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.
 

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,717
Messages
2,569,382
Members
44,705
Latest member
BerniePele

Latest Threads

Top