Welcome Guest Search | Active Topics | Sign In | Register

Downloader erros with huge files Options
EDP
Posted: Monday, June 20, 2011 8:54:50 AM
Rank: Member
Groups: Member

Joined: 11/15/2010
Posts: 23
Hi..

i have a page with downloader control with dymanic content.

Protected Overrides Sub GenerateContent()
Dim i As Integer
'Get the argument we passed in
Dim Argumentos As String
Dim Argumentos_Split As String()

Dim Ruta_Fichero_a_Descargar As String = ""
Dim Fichero_a_Descargar As String = ""
Dim Fichero_a_Descargar_Kb As Long

Argumentos_Split = Me.Arguments(i).Split("[SEPARADOR]")
Argumentos = Me.Arguments(i)

Ruta_Fichero_a_Descargar = Argumentos.Substring(0, Argumentos.IndexOf("[SEPARADOR]"))
Argumentos = Argumentos.Replace(Ruta_Fichero_a_Descargar & "[SEPARADOR]", "")

Fichero_a_Descargar = Argumentos.Substring(0, Argumentos.IndexOf("[SEPARADOR]"))
Argumentos = Argumentos.Replace(Fichero_a_Descargar & "[SEPARADOR]", "")

Fichero_a_Descargar_Kb = Integer.Parse(Argumentos)

If Ruta_Fichero_a_Descargar <> "" And Fichero_a_Descargar <> "" And Fichero_a_Descargar_Kb <> 0 Then

SetFileName(Fichero_a_Descargar, Round(Fichero_a_Descargar_Kb * 1024, 0))

'Generates the content
Dim Fichero_Origen As New FileStream(Ruta_Fichero_a_Descargar & Fichero_a_Descargar, FileMode.Open)
Dim Datos_Origen As Byte()
ReDim Datos_Origen(Fichero_Origen.Length)

Fichero_Origen.Read(Datos_Origen, 0, Fichero_Origen.Length)
Fichero_Origen.Close()

Write(Datos_Origen, 0, Datos_Origen.Length)

End If

Next

End Sub 'GenerateContent

But when i downloaded a huge file, file more than 200 Mb. an error ocurrs :

Se produjo una excepción de tipo 'System.OutOfMemoryException'

in line ReDim Datos_Origen(Fichero_Origen.Length)
eo_support
Posted: Monday, June 20, 2011 10:22:56 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
That's normal. This is your code error and has nothing to do with our downloader. You need to change your code so that you don't load the 200M file in memory at once.

Thanks
EDP
Posted: Wednesday, June 22, 2011 8:26:30 AM
Rank: Member
Groups: Member

Joined: 11/15/2010
Posts: 23
Hi, i change my code to download huge files and i don't need to store in memory. The code is:

BEGIN CODE

Dim Fichero_Origen As New FileStream(Ruta_Fichero_a_Descargar & Fichero_a_Descargar, FileMode.Open)

' Longitud del archivo:
Dim length As Integer

' Búfer para leer 10 KB en el fragmento:
Dim Tamanno_Buffer As Integer = 10000
Dim buffer(Tamanno_Buffer) As Byte

' Número total de bytes que leer:
Dim dataToRead As Long

Try
' Número total de bytes que leer:
dataToRead = Fichero_Origen.Length

' Leer los bytes.
While dataToRead > 0
' Leer los datos del búfer
length = Fichero_Origen.Read(buffer, 0, Tamanno_Buffer)

' Escribir los datos en la secuencia de salida actual.
Write(buffer, 0, length)

' Vaciar los datos en la salida HTML.
ReDim buffer(Tamanno_Buffer)

' Limpiar el búfer
dataToRead = dataToRead - length
End While

Catch ex2 As Exception

End Try
Fichero_Origen.Close()

END CODE

But when i downloaded files and i try to open and error ocurrs that the file is corrupted.

Why?? i don't understan which is the error code?

Thank you
EDP
Posted: Friday, June 24, 2011 2:39:37 AM
Rank: Member
Groups: Member

Joined: 11/15/2010
Posts: 23
Hi, again.. the code behind works fine whit files smaller than 4 Mb, but with greater files not works. When the file is over 99 % stop it and don't endind the downloaded. Why? i don't undertans why not works.

Dim Fichero_Origen As New FileStream(Ruta_Fichero_a_Descargar & Fichero_a_Descargar, FileMode.Open)

Dim length As Integer
Dim Tamanno_Buffer As Integer = 1024
Dim buffer(Tamanno_Buffer) As Byte

length = Fichero_Origen.Read(buffer, 0, Tamanno_Buffer)
While length > 0
Write(buffer, 0, length)

ReDim buffer(Tamanno_Buffer)

length = Fichero_Origen.Read(buffer, 0, Tamanno_Buffer)
End While

Fichero_Origen.Close()
eo_support
Posted: Friday, June 24, 2011 7:24:32 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

I do not believe any questions you mentioned in this thread have anything to do with us. We do not review or troubleshoot your code. I hope you understand.

Thanks
EDP
Posted: Friday, June 24, 2011 7:28:22 AM
Rank: Member
Groups: Member

Joined: 11/15/2010
Posts: 23
Sorry, but the code only fails in donwloader control with DynamicContent="TRUE", for this reason i posted.

Thank you
eo_support
Posted: Friday, June 24, 2011 7:33:27 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

That's because your code is only called when DynamicContent is set to true. The sample code works fine. So you may want to compare your code with the sample code to see if you can find the problem. We will not debug your code. So you can't just post your code and ask us to find out what's wrong with it.

Thanks
EDP
Posted: Monday, July 4, 2011 3:23:20 AM
Rank: Member
Groups: Member

Joined: 11/15/2010
Posts: 23
Hi and thank you for the time to answer the question. Sorry for reply again but my problem is that the code works perfectly when i donwloaded files about 4 mb or less but greater files fails. This is the only reason that i need help.

Why with grater files failed? i don't understand why not work.

Thank again and best regards
eo_support
Posted: Monday, July 4, 2011 8:57:07 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

Please try to isolate the problem into a test project and then send the test project to us. Make sure your test project runs independently and only contain code needed to reproduce the problem.

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.