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()
4

1 回答 1

0

我发现这是因为我的 Byte 数组中正好多了一个字节。正确的代码应该是

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()

似乎只有 Office 2010 文档会遇到这个额外字节的问题(设计使然?)。PDF、Office 97-2003 和其他不是。

于 2013-07-22T03:03:05.517 回答