Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8128175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:47:36+00:00 2026-06-06T07:47:36+00:00

I want to read a specific line from an html source code. Im storing

  • 0

I want to read a specific line from an html source code.
Im storing the source into a string file and i want to read the line X.
So im using this method that i found on net

Public Shared Function ReadSpecifiedLine(file As String, lineNum As Integer) As String
    Dim contents As String = String.Empty
    Try
        Using stream As New StreamReader(file)
            contents = stream.ReadToEnd()
            Dim linesArray As String() = contents.Split(New Char() {ControlChars.Lf})

            If linesArray.Length > 1 Then
                If Not lineNum > linesArray.Length AndAlso Not lineNum < 0 Then
                    Return linesArray(lineNum)
                Else
                    Return linesArray(0)
                End If
            Else
                Return contents
            End If
        End Using
    Catch ex As Exception
        Return ex.ToString()
    End Try
End Function

For example im trying to read the 4th line and im getting this error.

System.ArgumentException: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
at System.IO.Path.GetFileName(String path)
at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost)
at System.IO.StreamReader..ctor(String path)
at WindowsApplication1.Form1.ReadSpecifiedLine(String file, Int32 lineNum) in C:\Users\Optimus\documents\visual studio 2012\Projects\WindowsApplication1\WindowsApplication1\Form1.vb:line 48

Any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:47:43+00:00Added an answer on June 6, 2026 at 7:47 am

    The method you posted assumes you are passing in the file path. If you want to change it to accept the actual file contents, instead of the file path, you could simplify the method by getting rid of the stream object:

    Public Shared Function ReadSpecifiedLine(contents As String, lineNum As Integer) As String
        Dim linesArray As String() = contents.Split(New Char() {ControlChars.Lf})
        If linesArray.Length > 1 Then
            If Not lineNum > linesArray.Length AndAlso Not lineNum < 0 Then
                Return linesArray(lineNum)
            Else
                Return linesArray(0)
            End If
        Else
            Return contents
        End If
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to read an html file by using jquery get function, replace some
I want to read from a file each line and edit only the lines
I'm trying to read a specific line from a file and I can get
I am using following code to read text from a .txt file. But I
I'm using the following StreamReader to read from text file string temp = fs.ReadToEnd
I want to read a specific line of a RSS feed to display the
Hi I can't understand this error I want read this XML file: <?xml version=1.0
I want to read a INI file from python, and I came up with
I have a fixed format file. I want to access specific lines in this
I have a file that I want to read in using the File::Slurp module

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.