Hi,
please look at this code, it's very simple console application, just read some binary file from hard drive and convert it to ToBase64String so it can be sent by email. Problem with this code is that when it read file with size of 36Mb program allocate about 500Mb ?!? Can sombody tell me why, what I'm missing?
thanks jCode:Imports System.IO Imports System.Text Module Module1 Sub Main() Dim fs As FileStream = File.OpenRead("c:\test") Dim base64String As New StringBuilder(Convert.ToInt32((fs.Length + 1000))) Dim Header As New StringBuilder(Convert.ToInt32((fs.Length + 1000))) Dim binaryData() As Byte = New [Byte](fs.Length) {} Dim bytesRead As Long = fs.Read(binaryData, 0, CInt(fs.Length)) fs.Close() base64String.Append(System.Convert.ToBase64String(binaryData, 0, binaryData.Length)) Dim i As Integer While i < base64String.Length Dim nextchunk As Integer = 100 If base64String.Length - (i + nextchunk) < 0 Then nextchunk = base64String.Length - i End If Header.Append(base64String.ToString(i, nextchunk)) Header.Append(ControlChars.Cr + ControlChars.Lf) i += nextchunk End While Console.ReadLine() End Sub End Module




Reply With Quote