• Increase font size
  • Default font size
  • Decrease font size

How to create text file, write text file, and read text file in VB .Net?

E-mail Print PDF

This article shows you how to write Visual Basic .Net code to create Text File, write text into Text File and read content from Text File.

When we request to write text into Text File it will check first whether Text File does exist or does not. If it does not exist it will create new Text File automatically. Otherwise it will append text into the existing text file.

Write text into Text File
Dim sw As New System.IO.StreamWriter("C:\txttest.txt", True)

MsgBox("Save completed!")
Me.txtWrite.Text = ""
Read content from Text File
Dim sr As New System.IO.StreamReader("C:\txttest.txt")
Dim str As String
   str = sr.ReadLine()
   Me.txtRead.Text += str + vbCrLf
Loop Until sr.EndOfStream = True

Download Source Code