See more: VB.NET
Hi .. I'm working on a project that reads a text file. I open the file using READBLOCK. I get an error when opening big files. No issues when opening a 10MB file but got an error when opening a 1GB file.

Here's the part of the code that opens/reads the file:
Const MAX_BYTES As Integer = 1048576 * 5 '=10 MB
Dim currentPos As Integer = 0
Dim strFileName As String
Dim strm As System.IO.Stream
Dim TextLine As String
Dim FileDetail As IO.FileInfo

OpenFileDialogMain.ShowDialog()
strm = OpenFileDialogMain.OpenFile()
strFileName = OpenFileDialogMain.FileName.ToString()

End Using

txtEditor.Text += TextLine
txtEditor.Text = txtEditor.Text & vbCrLf & Now
Does anyone have any suggestion on how to open a large file?

Thanks!
Posted 19-Jun-12 18:48pm
Edited 19-Jun-12 18:49pm
JF201552.2K
v2

very good tanks
abb_saleh - 22-Feb-13 15:10pm

## Solution 1

If you want to read it all into memory, a simple File.ReadAllText() will do just fine. If your file is indeed very large, then you can use the StreamReader class, see the below approach. It is sometimes inevitable but should mostly be avoided for style reasons.

im file As New FileInfo("path\to\file")

ProcessLine(nextLine)
End While
End Using


Thanks for the quick response. I tried the "ReadAllText" and "ReadLine" before and I get the same error when opening a large file.
sdcruise - 20-Jun-12 0:59am

## Solution 2

Got a problem with ProcessLine, it says 'ProcessLine' is not declared. It may be inaccessible due to its protection level?
In response to your question about ProcessLine: ProcessLine seems to be a custom Sub here. Crappy example to point out the obvious: Dim TotalChars As Integer = 0 Private Sub ProcessLine(ByVal LineOfText As String) TotalChars = TotalChars + LineOfText.Count End Sub In this case ProcessLine would help you count the total amount of chars in your file. Hope that was helpful.
OneInNineMillion - 17-Jan-13 3:03am

 Interested Ignored

 0 Sergey Alexandrovich Kryukov 1,632 1 OriginalGriff 448 2 Maciej Los 400 3 CPallini 393 4 Tadit Dash 339
 0 Sergey Alexandrovich Kryukov 13,987 1 OriginalGriff 9,085 2 thatraja 4,220 3 Maciej Los 4,125 4 CPallini 3,784

Web03 | 2.7.131216.3 | Last Updated 17 Jan 2013