kantplayalik
Member
- Joined
- Mar 17, 2006
- Messages
- 7
- Programming Experience
- 1-3
Hello all, I find myself faced with a problem. I'm writing a vb,net application (2005) to do a one way file transfer. I've done this kind of thing before without too many headaches at work. However, I'm going to be sending VERY large files upwards of 5 Gigs and the code I have won't handle it...I keep getting an out of memory exception. Here is a snippet.
Any ideas on what I should do differently ?
Thanks in advance for your repiles/comments.
VB.NET:
Dim fileLength As Long = fi.Length
Dim fs As New FileStream(filename, FileMode.Open, FileAccess.Read)
Dim bytesWritten As Integer = 0
Dim bytesdone As Integer = 0
Dim fileData(1024 * 1024) As Byte
Dim tmp As Integer = 0
Do
bytesWritten = fs.Read(fileData, 0, fileData.Length)
If bytesWritten > 0 Then
If bytesWritten >= fileData.Length And (fileLength - bytesdone) >= fileData.Length Then
tmp = fileData.Length
ElseIf bytesWritten < fileData.Length And (fileLength - bytesdone) >= fileData.Length Then
tmp = bytesWritten
Else
tmp = Convert.ToInt32((fileLength - bytesdone))
End If
End If
ns.Write(fileData, 0, tmp)
bytesdone += tmp
Console.WriteLine(Convert.ToString(bytesdone) & " Of " & size)
Loop While (bytesdone < fileLength)
Thanks in advance for your repiles/comments.
Last edited by a moderator: