原始的office文件没有问题(我尝试了word和excel),但是当我将文件作为二进制文件上传到数据库然后从那里下载到我的PC并打开下载的文件时,我收到警告消息“找到excel内容无法读取”等,并且与原始文件相比,文件变得更加清晰。
确切的错误信息是;“Excel 在 filename.xls 中发现了不可读的内容。是否要恢复此工作簿的内容?如果您信任此工作簿的来源,请单击“是”。
我如何上传文件:
'UPLOAD FILE
Dim fi As New FileInfo(FilePath)
Dim s As Stream = fi.OpenRead()
Dim buffer(fi.Length) As Byte 'I put the buffer in database in varbinary(max) format
s.Read(buffer, 0, fi.Length)
s.Close()
我如何下载和打开文件:
'DOWNLOAD FILE
Dim fi As New FileInfo(FilePath)
Dim s As Stream = fi.OpenWrite()
Dim buffer As Byte() = reader("Binary")
s.Write(buffer, 0, buffer.Length)
s.Close()
'OPEN FILE
Dim p As New Process
p.StartInfo = New ProcessStartInfo(FilePath)
p.Start()
更新:
正如建议的那样,我尝试简单地复制文件,将 SQL 完全排除在外。这是我尝试过的代码,但也失败了:
Private Sub CopyFile(ByVal filePath As String)
Dim fi As New FileInfo(filePath)
Dim s As Stream = fi.OpenRead()
Dim buffer(CType(fi.Length, Integer) - 1) As Byte
s.Read(buffer, 0, CType(fi.Length, Integer))
s.Close()
Dim fi2 As New FileInfo(filePath & " Copy")
Dim s2 As Stream = fi2.OpenWrite()
s2.Write(buffer, 0, buffer.Length)
s2.Close()
End Sub