Read specific line with StreamReader

I'm using the attached code to read the first line of a text file using StreamReader.

How do I read specific lines? I only want the third line in this instance. (Peek?)
Dim Str As System.IO.Stream
        Dim srRead As System.IO.StreamReader

            Dim req As System.Net.WebRequest = System.Net.WebRequest.Create("http://Somewebsite/file.txt")
            Dim resp As System.Net.WebResponse = req.GetResponse
            Str = resp.GetResponseStream
            srRead = New System.IO.StreamReader(Str)

            Return srRead.ReadLine

            srRead.Close()
            Str.Close()

Open in new window

LVL 1
madlanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lazyberezovskyCommented:
No indexing is available.
Use ReadLine if you need to read specific lines.

E.g:
Const lineIndexToRead As Integer = 1
Dim line As String
Dim lineIndex As Integer = 0
While (line = srRead.ReadLine()) <> Nothing
	If lineIndex = lineIndexToRead Then
		'process line here
	End If

	lineIndex = lineIndex + 1
End While

Open in new window

0
käµfm³d 👽Commented:
To get the third line using your code, just call ReadLine() twice before you actually capture the important line:
Dim Str As System.IO.Stream
Dim srRead As System.IO.StreamReader

Dim req As System.Net.WebRequest = System.Net.WebRequest.Create("http://Somewebsite/file.txt")
Dim resp As System.Net.WebResponse = req.GetResponse
Str = resp.GetResponseStream
srRead = New System.IO.StreamReader(Str)

srRead.ReadLine
srRead.ReadLine

Return srRead.ReadLine

srRead.Close()
Str.Close()

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.