Wessel Beulink
Ваш ответ заключается в том, что файл WriteFile имеет длину документа для записи в блоки. Это int32, который в вашем случае слишком велик. попробовать это:
Using ms As New MemoryStream(doc.ByteArray)
Dim dataLengthToRead As Long = ms.Length
Dim blockSize As Integer = If(dataLengthToRead >= 5000, 5000, CInt(dataLengthToRead))
Dim buffer As Byte() = New Byte(dataLengthToRead - 1) {}
Response.Clear()
' Clear the content of the response
Response.ClearContent()
Response.ClearHeaders()
' Buffer response so that page is sent
' after processing is complete.
Response.BufferOutput = True
' Add the file name and attachment,
' which will force the open/cance/save dialog to show, to the header
Response.AddHeader("Content-Disposition", "attachment; filename=" + doc.FileName)
' bypass the Open/Save/Cancel dialog
Response.AddHeader("Content-Disposition", "inline; filename=" + doc.FileName);
' Add the file size into the response header
Response.AddHeader("Content-Length", doc.FileSize.ToString())
' Set the ContentType
Response.ContentType = "application/octet-stream"
' Write the document into the response
While dataLengthToRead > 0 AndAlso Response.IsClientConnected
Dim lengthRead As Int32 = ms.Read(buffer, 0, blockSize)
Response.OutputStream.Write(buffer, 0, lengthRead)
Response.Flush()
dataLengthToRead = dataLengthToRead - lengthRead
End While
Response.Flush()
Response.Close()
End Using
'End the response
Response.[End]()
' Write the document into the response
While dataLengthToRead > 0 AndAlso Response.IsClientConnected
Dim lengthRead As Int32 = ms.Read(buffer, 0, blockSize)
Response.OutputStream.Write(buffer, 0, lengthRead)
'Response.Flush(); // do not flush since BufferOutput = true
dataLengthToRead = dataLengthToRead - lengthRead
End While
Response.Flush()
Response.Close()