Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Downloading Office 2007 files from IE into client-side Office 2007 1

Status
Not open for further replies.

ChristianWhite

Programmer
Jun 14, 2004
41
0
0
US
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()
 
You could specify an unknown type such as "application/octet-stream" so that the OS decides which application to open it in. As long as you have set the filename of the stream to have the correct extension then it should work.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Thanks Mark--

Improvement number one, that causes IE 6 or 7 to return with the anticipated prompt to recognize the file and offer to Open or Save--which it wasn't doing before, when IE just seemed to quietly abort the operation.

Second, now that the prompt does appear for Office 2007 files as it has been doing for the other types, choosing Open for an Office 2007 file results in IE returning a new prompt that concedes it can not Open the file. Options given are Save or Cancel.

That's an improvement also, because users aren't confused by being shown a file folder upon clicking Open.

Where Microsoft IE has this problem, Mozilla Firefox still sails through without. Odd.

Again, many thanks. As phase two I think I'll be talking to the server admin, I wonder if the server may have to know what to do with the MIME types in order to open Office 2007 files into IE. Something knows what to do in order to open them into Firefox.
 
>That's an improvement also, because users aren't confused by being shown a file folder upon clicking Open.

Oops--I should mention, previously I did have one option if I didn't want IE to quietly abort--I would cause a file type application/x-zip-compressed to get entered in the case of a .docx or .xlsx file type. That's what caused the zipped archive to get opened as a file folder from IE. Only slightly more attractive than the process disappearing.
 
I'd guess it probably is a problem with IE then (as opposed to it being somethin we could rectify from a coding point of view). You could ask in the "Browser issues for IT professionals" forum to see if they have any experience on this or any suggestions to offer.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top