Monday, September 08, 2008

Office 2007 document upload - files corrupt

Adding a file to SharePoint can be implemented through a web service as described in the note from Microsoft. It works fine - for all types of documents except for Office 2007 documents!

Upload goes fine - but when you try to open the file using Office you get the following errors:




The Office Open XML file cannot be opened because there are problems with the content.

Solution

SharePoint seems to have an error when adding documents to the filecollecting using the

SPFolder.Files.Add

function. If you add from a byte-array it simply fails with Office 2007 documents. But if you convert the byte-array into a stream, e.g. by saving the byte-array into a file and loading it into a stream, then it works. It's unclear to me why this error occurs - but Microsoft probably drops a single byte in the byte-scenario - which is critical for Office 2007 documents, but other documents seems to survive.

Input and comments very much appreciated.

3 comments:

Alex said...

For work with excel files and similar type files I often use next tool-Excel file corrupted,because it helped myself many times,has free status as far as I remember,and utility can try Excel repairs manually, by retyping all documents, but it is time consuming, you can spend many days for this purpose, when Excel file has corrupted,tool for Excel repairing is very easy to use, when Excel file corrupted, it has only several buttons and functions for Excel document repair: open file, start its analysis, preview of recovered contents and export of recovered data into a new document in Microsoft Excel format,allows to perform all steps and take a look into recovered contents of this file.

Suresh said...

Alex, I faced the similar problem for Word doc and I tried the tool you have mentioned but that didn't work.
Morten, could you able to solve this issue?

Alex said...

My uncle send me a letter where he asked about excel problem. I advised him a tool, which I was found some days ago. To my great surprise, he thanked me a lot and besides I believe that this tool would be useful for any situation with excel files - excel spreadsheet repair.