size参数必须介于0和VB中的最大int32值之间 [英] The size parameter must be between zero and the maximum int32 value in VB

查看:149
本文介绍了size参数必须介于0和VB中的最大int32值之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我需要下载非常大的zip文件:我有这样的错误,下载如何解决这个问题:



 size参数必须介于0和最大Int32值之间。参数名称:大小实际值为5528988753。





我尝试过:



受保护的子DownloadFile(ByVal sender As Object,ByVal e As EventArgs)
Dim filePath As String = CType(sender,ImageButton).CommandArgument
Response.ContentType = ContentType
Response.AppendHeader(Content-Disposition,(attachment; filename =+ Path.GetFileName(filePath)))
Response.WriteFile(filePath)
Response.End()
End Sub

解决方案

文件太大:字节数不符合标准整数(只能保存-2,147,483,648和2,147,483,647之间的值。您的文件是5,528,988,753字节,无法传输。



将文件压缩成多部分存档,并传输它在较小的块中。


你的响应是为了使WriteFile有一个文档长度用于写在街区。这是一个int32,在你的情况下很大。试试这个:



使用ms作为新的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()


'清除回复的内容
Response.ClearContent()
Response.ClearHeaders()


'缓冲区响应,以便在处理完成后页面被发送
'。
Response.BufferOutput = True


'添加文件名和附件,
'将强制打开/取消/保存对话框显示到标题
Response.AddHeader(Content-Disposition,attachment; filename =+ doc.FileName)


'绕过打开/保存/取消对话框
Response.AddHeader(Content-Disposition,inline; filename =+ doc.FileName);


'将文件大小添加到响应头中
Response.AddHeader(Content-Length,doc.FileSize.ToString())


'设置ContentType
Response.ContentType =application / octet-stream


'将文档写入响应
而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


Response.Flush()
Response.Close()
End using


'结束回复
回复。[结束]()





'将文档写入响应
而dataLengthToRead> 0 AndAlso Response.IsClientConnected
Dim lengthRead As Int32 = ms.Read(buffer,0,blockSize)
Response.OutputStream.Write(buffer,0,lengthRead)
'Response.Flush() ; //不要刷新,因为BufferOutput = true
dataLengthToRead = dataLengthToRead - lengthRead
End while

Response.Flush()
Response.Close()


Dear Friends,

I need to download very large zip files: i have an error like this while download how to solve this:

The size parameter must be between zero and the maximum Int32 value. Parameter name: size Actual value was 5528988753.



What I have tried:

Protected Sub DownloadFile(ByVal sender As Object, ByVal e As EventArgs)
        Dim filePath As String = CType(sender, ImageButton).CommandArgument
        Response.ContentType = ContentType
        Response.AppendHeader("Content-Disposition", ("attachment; filename=" + Path.GetFileName(filePath)))
        Response.WriteFile(filePath)
        Response.End()
    End Sub

解决方案

The file is too big: the byte count does not fit into a standard integer (which can only hold values between -2,147,483,648 and 2,147,483,647. Your file is 5,528,988,753 bytes, and cannot be transferred.

ZIP the file into a multipart archive, and transfer it in smaller chunks.


Your response is to long the WriteFile has an document length for writing in blocks. This is a int32 which is to large in your case. try this:

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


这篇关于size参数必须介于0和VB中的最大int32值之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆