VB.NET Read the 3rd line of a text file only ?

How can i read the 3rd line of a text file only ?
LVL 1
VartanaAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
DotNetLover_BaanConnect With a Mentor Commented:
Hi there, use readLine method of a StreamReader.

        Dim StreamRd As FileStream
        'Check if the file is there.
        If File.Exists("C:\Data.txt") Then
            StreamRd = New FileStream("C:\Data.txt", FileMode.Open, FileAccess.Read)
        Else
            MsgBox("OOPS!! CEIP_Upload.txt not found")
            Exit Sub
        End If
        'Create reader and read from the file
        Dim FileReader As New StreamReader(StreamRd)
        TextBox1.Text = FileReader.ReadLine 'Show the first Line in a text box.
        'Read twice and you are in the 3rd line
        FileReader.Close()
-Baan
0
 
natlozConnect With a Mentor Commented:
oRead = oFile.OpenText(“C:\sample.txt”)
dim count = 1

 While oRead.Peek <> -1      
   if count = 3 then
      LineIn = oRead.ReadLine()
   end if
   count = count + 1
 End While

 oRead.Close()
0
 
VartanaAuthor Commented:
This dosnt work  How can i read the 3rd line ?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
DotNetLover_BaanCommented:
What do you mean it doesn't work... ?  I tested it.. and it is giving me the third line...
0
 
VartanaAuthor Commented:
ok it works sorry :(

Thank you much
0
 
DotNetLover_BaanCommented:
happy programming... :))
cheers...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.