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.
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.