Streamreader to read specific line

Posted on 2011-10-21
Last Modified: 2012-05-12
I am using visual studio 2005.How to use stream reader to read specific line number in a text?

Question by:RIAS
    LVL 17

    Expert Comment

    LVL 18

    Accepted Solution

    I just use a loop and dump the lines into a variable (an array if you want them all, a string if you just want the last one).

    For a = 0 To 4
      sTemp = oRead.ReadLine

    Author Comment

    StreamReader.BaseStream Property?
    LVL 18

    Expert Comment

    No. Just declare your streamreader and a string:

    Dim oRead As New IO.StreamReader(FileName)
    Dim sTemp As String

    Then use the loop above to read the 5th line. Change the value to read whichever line you wish to read.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now