ChristianWhite
Programmer
I’m working with the following code in ASP 1.1, SQL Server 2000 database.
Main test workstation has: Office 2007, IE 7
Secondary test workstation: Office 2003, IE 6
Fired by a link, the code at bottom of my post downloads to the client some content stored as a binary field in SQL, opening it in the browser or saving, depending on whether the user clicks Open or Save.
Firefox has no problem. IE 6/7 has no problem saving, nor opening most file types.
The problem: I can’t get Office 2007 files to open in IE in their original word processor or spreadsheet; older Office file types do.
I know Office 2007 files are zipped archives; if I specify the type in the SQL field, FileType, as zipped, IE does open a Windows folder showing the files. That’s not the response I’m wanting, though. For other file types such as Word 2003, IE opens up Word 2003 and displays the file looking as it did for the author-—why not for Word 2007? Instead, IE just quits and goes back to the application like no download operation happened.
Input appreciated.
Christian
Additional info
Values I’m entering into SQL Server for FileType:
Excel 2007 application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Word 2007 application/vnd.openxmlformats-officedocument.wordprocessingml.document
Word 2003 application/msword
Zipped archive application/x-zip-compressed
Code
'initialize
Dim cmd As SqlClient.SqlCommand
Dim sdaAttachments As SqlClient.SqlDataAdapter
Dim dsAttachments As DataSet
Dim SqlConnection1 As SqlClient.SqlConnection
Dim strSQL As String
sdaAttachments = New SqlClient.SqlDataAdapter
dsAttachments = New DataSet
SqlConnection1 = New SqlClient.SqlConnection
SqlConnection1.ConnectionString = Session("ConnectionString")
strSQL = "SELECT FileType, LocalFileName, Attachment " & _
" FROM tblAttachment " & _
" WHERE AttachmentID =" & Session("AttachmentID")
cmd = New System.Data.SqlClient.SqlCommand(strSQL, SqlConnection1)
'fill dataset
sdaAttachments.SelectCommand = cmd
sdaAttachments.Fill(dsAttachments)
'read file name, file type, and contents (the field named “attachment”) into the response
Response.AddHeader("Content-disposition", "inline;filename=" & dsAttachments.Tables(0).Rows(0)("LocalFileName"))
Response.ContentType = dsAttachments.Tables(0).Rows(0)("FileType")
Response.BinaryWrite(dsAttachments.Tables(0).Rows(0)("Attachment"))
'cleanup
dsAttachments.Dispose()
sdaAttachments.Dispose()
Response.Flush()
Main test workstation has: Office 2007, IE 7
Secondary test workstation: Office 2003, IE 6
Fired by a link, the code at bottom of my post downloads to the client some content stored as a binary field in SQL, opening it in the browser or saving, depending on whether the user clicks Open or Save.
Firefox has no problem. IE 6/7 has no problem saving, nor opening most file types.
The problem: I can’t get Office 2007 files to open in IE in their original word processor or spreadsheet; older Office file types do.
I know Office 2007 files are zipped archives; if I specify the type in the SQL field, FileType, as zipped, IE does open a Windows folder showing the files. That’s not the response I’m wanting, though. For other file types such as Word 2003, IE opens up Word 2003 and displays the file looking as it did for the author-—why not for Word 2007? Instead, IE just quits and goes back to the application like no download operation happened.
Input appreciated.
Christian
Additional info
Values I’m entering into SQL Server for FileType:
Excel 2007 application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Word 2007 application/vnd.openxmlformats-officedocument.wordprocessingml.document
Word 2003 application/msword
Zipped archive application/x-zip-compressed
Code
'initialize
Dim cmd As SqlClient.SqlCommand
Dim sdaAttachments As SqlClient.SqlDataAdapter
Dim dsAttachments As DataSet
Dim SqlConnection1 As SqlClient.SqlConnection
Dim strSQL As String
sdaAttachments = New SqlClient.SqlDataAdapter
dsAttachments = New DataSet
SqlConnection1 = New SqlClient.SqlConnection
SqlConnection1.ConnectionString = Session("ConnectionString")
strSQL = "SELECT FileType, LocalFileName, Attachment " & _
" FROM tblAttachment " & _
" WHERE AttachmentID =" & Session("AttachmentID")
cmd = New System.Data.SqlClient.SqlCommand(strSQL, SqlConnection1)
'fill dataset
sdaAttachments.SelectCommand = cmd
sdaAttachments.Fill(dsAttachments)
'read file name, file type, and contents (the field named “attachment”) into the response
Response.AddHeader("Content-disposition", "inline;filename=" & dsAttachments.Tables(0).Rows(0)("LocalFileName"))
Response.ContentType = dsAttachments.Tables(0).Rows(0)("FileType")
Response.BinaryWrite(dsAttachments.Tables(0).Rows(0)("Attachment"))
'cleanup
dsAttachments.Dispose()
sdaAttachments.Dispose()
Response.Flush()