How to read and write text file (.txt) in VB.net
Know More : ASP.Net VB.Net C#.Net Sliverlight XML WPF WCF Ajax
Let’s start ..In visual studio 2010\2008\2005\2003 edition, Firstly design your desktop application as shown in figure..
For design, you have drag some controls like one textbox or richtextbox,one Label and three buttons and rename it on form design also set textbox multiline properties true as shown in above figure..after do that go to form view code , first declare namespace like this…….
Imports System.IO
Public Class Form1
Dim fsteream As New FileStream("C:\Example.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite)
Dim sw As New StreamWriter(fsteream)
Private Sub Reset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Reset.Click
TextBoxX1.Text = ""
End Sub
Public Sub writedata(ByVal Data As String, ByVal sw As StreamWriter)
sw.WriteLine(Data)
sw.WriteLine("")
sw.Flush()
End Sub
Public Sub readdata(ByVal r As StreamReader)
TextBoxX1.Text = r.ReadToEnd
End Sub
Private Sub Write_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Write.Click
sw.BaseStream.Seek(0, SeekOrigin.End)
writedata(TextBoxX1.Text, sw)
Read.Enabled = True
Write.Enabled = False
TextBoxX1.Text = ""
End Sub
Private Sub Read_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Read.Click
Dim sr As New StreamReader(fsteream)
sr.BaseStream.Seek(0, SeekOrigin.Begin)
readdata(sr)
Read.Enabled = False
Write.Enabled = True
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Now start debugging from debug menu or press f5 button, After debug your application Output as shown in figure ……
after type, click on “write” button and also click on read button.Now your text file is complete for read and write.Thanks.
Know More : ASP.Net VB.Net C#.Net Sliverlight XML WPF WCF Ajax
Let’s start ..In visual studio 2010\2008\2005\2003 edition, Firstly design your desktop application as shown in figure..
For design, you have drag some controls like one textbox or richtextbox,one Label and three buttons and rename it on form design also set textbox multiline properties true as shown in above figure..after do that go to form view code , first declare namespace like this…….
Imports System.IO
Public Class Form1
Dim fsteream As New FileStream("C:\Example.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite)
Dim sw As New StreamWriter(fsteream)
Private Sub Reset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Reset.Click
TextBoxX1.Text = ""
End Sub
Public Sub writedata(ByVal Data As String, ByVal sw As StreamWriter)
sw.WriteLine(Data)
sw.WriteLine("")
sw.Flush()
End Sub
Public Sub readdata(ByVal r As StreamReader)
TextBoxX1.Text = r.ReadToEnd
End Sub
Private Sub Write_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Write.Click
sw.BaseStream.Seek(0, SeekOrigin.End)
writedata(TextBoxX1.Text, sw)
Read.Enabled = True
Write.Enabled = False
TextBoxX1.Text = ""
End Sub
Private Sub Read_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Read.Click
Dim sr As New StreamReader(fsteream)
sr.BaseStream.Seek(0, SeekOrigin.Begin)
readdata(sr)
Read.Enabled = False
Write.Enabled = True
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Now start debugging from debug menu or press f5 button, After debug your application Output as shown in figure ……
after type, click on “write” button and also click on read button.Now your text file is complete for read and write.Thanks.
Know More : ASP.Net VB.Net C#.Net Sliverlight XML WPF WCF Ajax
Fortunately, you can simplify this task by reading some
ReplyDeletereviews and articles on mmorpgs. Rockhopper has his faithful
companion, Yarr, a red puffle who travels the on the Migrator
with Rockhopper. (At this point, you can determine whether
your pony will have a shorter mane, like a traditional
hunter-jumper, or a long and luxurious one, like a Baroque horse.
Feel free to visit my blog; article writing wizard (www.germinaciones.org)