Office 2007 (.docx) to database

C

charleswesley

I have a document management tool I have built as a Web app. It takes
a file a user submits and saves it to a table in a SQL 2000 database
(Image datatype).

I have a download.aspx file that returns a file the user has
requested.

This has worked for all files I have tested against except for Office
2007 files.

For example, when a user requests test.docx, they are prompted to save
as or open the file.

Regardless of which option they choose, when they open the file Word
2007 displays the following error dialogue boxes:

"The Office Open XML file Test.docx cannot be opened because there are
problems with the contents."

Details:

"The file is corrupt and cannot be opened."

Word 2007 then "recovers" the contents of the document by clicking
"OK" to a dialogue prompt, and the file is there w/ all of its
content.

By reading the file into a binary array and saving to the database,
and then returning the file upon request, something is getting
garbled.

Is there a "right" way to save an Office 2007 document to a database?
Why wouldn't my current method work?
 
R

Rad [Visual C# MVP]

I have a document management tool I have built as a Web app. It takes
a file a user submits and saves it to a table in a SQL 2000 database
(Image datatype).

I have a download.aspx file that returns a file the user has
requested.

This has worked for all files I have tested against except for Office
2007 files.

For example, when a user requests test.docx, they are prompted to save
as or open the file.

Regardless of which option they choose, when they open the file Word
2007 displays the following error dialogue boxes:

"The Office Open XML file Test.docx cannot be opened because there are
problems with the contents."

Details:

"The file is corrupt and cannot be opened."

Word 2007 then "recovers" the contents of the document by clicking
"OK" to a dialogue prompt, and the file is there w/ all of its
content.

By reading the file into a binary array and saving to the database,
and then returning the file upon request, something is getting
garbled.

Is there a "right" way to save an Office 2007 document to a database?
Why wouldn't my current method work?

Have you tried using some soft of diff tool to see if there's a
difference between the original file and the streamed file? Perhaps
the web server is adding something to the end of the file
 
C

charleswesley

Have you tried using some soft of diff tool to see if there's a
difference between the original file and the streamed file? Perhaps
the web server is adding something to the end of the file

--http://bytes.thinkersroom.com

Thanks for the suggestion -- I opened up the original file and the
streamed file using Hex Workshop:

http://www.download.com/Hex-Workshop/3000-2352_4-10004918.html?tag=pdp_prod&pid=10264932

I did find a difference. The streamed file has what appears to be
have something extra.

Original (9,932 bytes):

0000 0000

Streamed (9,933 bytes):

0000 0000 00

I don't have much experience streaming files, so I'm not sure where
the extra byte is coming from. I am going to review my code, but in
the meantime if anyone has any suggestions I'm open.

Thanks again
 
C

charleswesley

Thanks for the suggestion -- I opened up the original file and the
streamed file using Hex Workshop:

http://www.download.com/Hex-Workshop/3000-2352_4-10004918.html?tag=pd...

I did find a difference. The streamed file has what appears to be
have something extra.

Original (9,932 bytes):

0000 0000

Streamed (9,933 bytes):

0000 0000 00

I don't have much experience streaming files, so I'm not sure where
the extra byte is coming from. I am going to review my code, but in
the meantime if anyone has any suggestions I'm open.

Thanks again

Solution: When streaming the file back, I had the content-length = the
size of the file, when it should have been (size - 1)

Thanks for the suggestion. Sorry it was such an easy solution :(
 
R

Rad [Visual C# MVP]

Solution: When streaming the file back, I had the content-length = the
size of the file, when it should have been (size - 1)

Thanks for the suggestion. Sorry it was such an easy solution :(

Not to worry. This is a lesson I keep learning time and time again.
Life is funny in that sometimes the most complex of problems generally
have the simplest of solutions!
 

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,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top