Write Data Into A Text File Using VB.NET
The example below shows how you can open a textfile ( .txt) and write the data by using VB.NET. Assuming the text file "contact.txt" stored in C:\ drive contains the following 3 lines (Name, Contact Number and Address)
----------------------contact.txt---------------------
Kimberly Wood
570-897-7676227
Main Avenue PO Box 987, Palmerton, PA 18071
------------------------------------------------------
The codes below show you how to write these data into a text file using VB.NET. You might need to include System.IO in your project reference section before you can execute the code.
'-----declare Variables
Dim Name, ContactNo, Address As String
Dim fs as New FileStream("C:\contact.txt", FileMode.Create, FileAccess.Write)
Dim ws as New StreamReader(fs)
ws.WriteLine(Name) '--- Write Name into Line 1
ws.WriteLine(ContactNo) '--- Write Name into Line 2
ws.WriteLine(Address) '--- Write Name into Line 3
ws.Close()
Hence, the three lines of data from the text file have been written and stored in the text file.
See Also How To Read Data From A Text File using VB.NET
See Also How To Read Data From A Text File using VB6 / Classic
See Also How To Write Data Into A Text File using VB6 / Classic
VB.NET : Write Data Into A Text File
Posted by Fluffy | 3:25 AM | VB.NET, Write Data Into A Text File VB.NET | 0 comments »
Subscribe to:
Post Comments (Atom)

0 comments
Post a Comment