Click here to Skip to main content
15,919,613 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to read a text file with only 2 Lines and show them in text boxes here is my code (from MSDN) but cannot figure out how to continue:
Dim fileReader As System.IO.StreamReader
fileReader = My.Computer.FileSystem.OpenTextFileReader("C:\Program Files\login.conf")
        Dim str1, str2 As String

and have the first Line of the txt file in variable str1 and second in str2 like this :
textbox1.text = str1
textbox2.text = str2
Updated 28-Oct-15 5:22am

Share this answer
Sergey Alexandrovich Kryukov 28-Oct-15 11:31am    
Member 3892343 28-Oct-15 11:37am    
ZurdoDev 28-Oct-15 11:54am    
You're welcome.
Maciej Los 28-Oct-15 15:43pm    
Use File.ReadAllLines Method

Public Shared Function ReadAllLines (
    path As String
) As String()


Imports System
Imports System.IO

Public Class Test
    Public Shared Sub Main()
        Dim path As String = "c:\temp\MyTest.txt"
        Dim sw As StreamWriter

        ' This text is added only once to the file.
        If File.Exists(path) = False Then

            ' Create a file to write to.
            Dim createText() As String = {"Hello", "And", "Welcome"}
            File.WriteAllLines(path, createText)
        End If

        ' This text is always added, making the file longer over time
        ' if it is not deleted.
        Dim appendText As String = "This is extra text" + Environment.NewLine
        File.AppendAllText(path, appendText)

        ' Open the file to read from.
        Dim readText() As String = File.ReadAllLines(path)
        Dim s As String
        For Each s In readText
    End Sub
End Class

hope it would resolve your issue
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900