Click here to Skip to main content
15,896,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 10-Apr-17 22:00pm
Comments
Wessel Beulink 11-Apr-17 3:52am    
What type is ContentType? If you talking about 'Large' use int64 and long types instead.
Vivek.anand34 11-Apr-17 3:53am    
where i use int64 i not declared any int values

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.
 
Share this answer
 
v2
Comments
Vivek.anand34 11-Apr-17 4:35am    
Then how to download that kind of files.
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()
 
Share this answer
 
v3
Comments
Vivek.anand34 11-Apr-17 4:33am    
What is doc here... Using ms As New MemoryStream(doc.ByteArray)
Wessel Beulink 11-Apr-17 4:53am    
For you your blob of the zip.
Something like:
Dim doc As New FileStream("C:\Temp\result.zip", FileMode.Open)
Vivek.anand34 11-Apr-17 4:58am    
bytearray as not a member of system.io.filestream
Wessel Beulink 11-Apr-17 5:12am    
You need convert it ofcorse.
Use this else: byte [] data=File.ReadAllBytes("C:\\file.zip");
Vivek.anand34 11-Apr-17 5:54am    
I used code from this site: its executed..

https://www.codeproject.com/Tips/842832/How-to-Download-Large-Files-from-ASP-NET-Web-Forms

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900