Visual Basic Online Course - VB .NET Read Text File
Visual Basic 2010 - How to Read Text File(s)
VB .NET Read Text Files |
In order to read from a Text File then a Text File has to be present (Present = Known Path), the path of a Text File is just like any other path of any file it is String, for example :
C:\Folder\File.txt
The path to the File.txt is (C:\Folder\File-Name.Extension), so the path to the File Text = Path + File-Name + extension. Text Files can be present locally (on the same machine) or from external place (on the web) for example :
ftp://10.0.0.27/Folder/File.txt
As long as this Path is present and accessible then Reading Text File in VB 2010 is just so easy job to do. We can store the path to the Text File into a String variable to use it in our VB 2010 project :
Dim LocalFilePath as String = ("C:\Folder\File.txt")Dim WebFilePath As String = ("ftp://10.0.0.27/Folder/File.txt")
The problem with Text Files hosted on the web, is that it has to be accessible in order to read it or write it, you have to provide a User Name and Password to gain access to those files for most of the times because of security issues, unlike reading Text Files from local storage devices, there is no need to provide credentials or authentications to be able to read them.
Reading from Local Text Files in VB 2010
We will use File Reader to read String stored in a Text File,we will use basics of reading Text Files.
- Create VB 2010 Windows Form Project (WindowsApplication1) and save it to (D:\)
- Add TextBox (Name : TxtFromFile, MultiLine : True)
- Create Text File (MyFile.txt) and place it in the project folder Path to MyFile.txt is (D:\WindowsApplication1\Bin\Debug\)
- Write to MyFile.txt those two lines :
Hello
Visual Basic Online Course
5) Save and close the file.
Now, the project will :
- Open the Text File to read on the Form_Load() event
- Displays the String in the TextBox (TxtFromFile)
Code
♥ Here are some online Visual Basic lessons and courses :
- Visual Basic .Net - Snippets collection
- Visual Basic .Net - How to check for the internet connection
- Visual Basic .Net - POP3 and Receiving E-mails
- Visual Basic .Net - Generate Random Combinations
- Visual Basic .Net - Play sounds on Button Click or Mouse Hover
- Visual Basic .Net - Progressbar control
- Visual Basic .Net - The application failed to initialize
- Visual Basic .Net - Working with Database full example
- Visual Basic .Net - There is already an open DataReader associated
- Visual Basic .Net - SyBase Advantage Database [Add, Edit, Search, Delete and DataGridView]
- Visual Basic .Net - Math Functions
- Visual Basic .Net - Communicating with clients [Requirements Docs, Use-Case]
- Visual Basic .Net - Receive Emails using POP3 mail Server
- Visual Basic .Net - Command Prompt
- Visual Basic .Net - Free POS System Project Source Code