0

I currently upload document to SharePoint 2010 document library using ASP FileUpload control.

The process works fine for OFfice 92-2003 documents, TXT, RTF and even PDF until it meets Office 2010 documents.

The problem is: You can upload the file successfully. The file is there on the SharePoint server. But after downloading to local, open the file will show that the file has unreadable content (or corrupt) and need to recover to read. After recovering, it opens normally. XLSX file

I recall reading somewhere that Office 2010 documents uploading stream is slightly different from Office 2003 but don't remember how it exactly is.

This is my code:

ASPX

<asp:FileUpload ID="UploadControl" runat="server" onchange="FileChooseAction()" />

Code Behind

Dim byt As Byte()
ReDim byt(UploadControl.PostedFile.InputStream.Length)
UploadControl.PostedFile.InputStream.Seek(0, SeekOrigin.Begin)
UploadControl.PostedFile.InputStream.Read(byt, 0, UploadControl.PostedFile.InputStream.Length)
UploadControl.PostedFile.InputStream.Close()

1 Answer 1

0

I found out it is because of exactly one extra byte from my Byte array. The right code should be

Dim byt As Byte()
ReDim byt(UploadControl.PostedFile.InputStream.Length - 1)
UploadControl.PostedFile.InputStream.Seek(0, SeekOrigin.Begin)
UploadControl.PostedFile.InputStream.Read(byt, 0, UploadControl.PostedFile.InputStream.Length - 1)
UploadControl.PostedFile.InputStream.Close()

It seems only Office 2010 documents run into trouble with this extra byte (by design?). PDF, Office 97-2003 and others aren't.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.