reading lines in a text file after selecting from a File Chooser

F-U

New member
Joined
May 17, 2005
Messages
2
Programming Experience
Beginner
Hi There,​

The following code here is abt choosing a file from a file chooser and capturing the contents of that file:

VB.NET:
[size=2]
dlgOpen.InitialDirectory = "C:\Desktop"
dlgOpen.Filter = " D (*.doc;*.htm;*.html *.txt; *.rtf; *.xls; *.xlw)| *.doc; *.htm; *.html; *.txt; *.rtf; *.xls; *.xlw"
[size=2]dlgOpen.RestoreDirectory = [/size][size=2][color=#0000ff]True[/color][/size]
[size=2][color=#0000ff]If[/color][/size][size=2] dlgOpen.ShowDialog() = DialogResult.OK [/size][size=2][color=#0000ff]Then [/color][/size]
[color=#0000ff]		 [size=2]Dim[/size][/color][size=2] display [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] System.IO.StreamReader(dlgOpen.FileName[/size]
[size=2]		 txttext.Text = (display.ReadToEnd)[/size]
[size=2]		 display.Close()
[/size]

My qn is if there is a way to read a line of the selected text file for instance and then put in arrays of string? do i need a stream reader for this?

thanks
[/size]
 
Use ReadLine instead of ReadToEnd. You might want to add each string returned by ReadLine to an ArrayList, which dynamically resizes, rather than an Array. If you specifically need an Array the ArrayList class has a ToArray method that you can call once all lines have been read.
 
Back
Top