There are times that we need to create a text file specially if our systems want's to send or exchange data with other systems. Text file or .txt file extentions are one of the few standards in sending data. It can easily open in a notepad program.
In this blog, I just want to share some codes on how to create a text file and write data or open the file and read data contents. I am using the System.IO which is available in .Net library.
Here's the code in creating and writing a text data;
Dim MyFile As System.IO.File
Dim MyWriter As System.IO.StreamWriter
MyWriter = MyFile .CreateText("C:\sample.txt")
MyWriter.WriteLine("RFID,Client,JobNumber,ObjectNumber,ItemDescription,Notes")
MyWriter.WriteLine("000000000000000000621211,Jones,62121,1,First painting,in Lobby")
The Writeline method writes the string in one line and the next string will follow on the next line while the Write method writes the string continuously.
Here's the code for opening and reading a text file;
Dim MyFile as System.IO.File
Dim MyReader as System.IO.StreamReader
MyReader = MyFile.OpenText(“C:\sample.txt”)
That's it. Just a few lines of codes and we're done. You have now a text reader and writer for .Net.
Thanks again for reading my blog.
Happy Holidays and Happy Coding too!
No comments:
Post a Comment