Vb.Net Read Text File


This article is written by Pon Saravanan  on 17-Dec-10 Last modified on :08-Feb-11





VB.Net Tutorial - Read Text File using VB6

In classic VB reading a file is not that easy as we do in vb.net. The first and easy way to access a text file is using the simple file open method available in classic Visual Basic. Using this method, we can allocate a unique file number for opening the file. further the same number has to be used for closing the file handle.

In addition to this, there are various modes a file can be opened. Some of them are Append, Binary, Input, Output, or Random. By default Random will be used.

Read text file in VB.Net

In VB.net we can read files very easily. The System.IO namespace contains really very useful set of functions which can reduce the effort and time in coding file related activities. One of the easiest is reading a text file into string System.IO.File.ReadAllText(FilePath).

Source code

Form1.Vb

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
                    ByVal e As System.EventArgs) Handles Button1.Click
        TextBox2.Text = System.IO.File.ReadAllText(TextBox1.Text)
    End Sub
End Class











Comments
  • GUEST
    VERY FINE CODE IS AVALIABLE HERE. 4/7/2011 5:26:34 AM

  • GUEST
    7/29/2011 5:17:07 AM

  • GUEST
    8/25/2011 12:40:14 AM

  • GUEST
    i agree.
    but the articles is a bit hard to read since the color is dim.
    2/7/2012 1:33:04 AM

  • GUEST
    Hi,
    any body knows how to remove some columns from print preview.
    Thanks
    8/11/2012 3:52:44 PM


Comments
   
Captcha Image
For you specially:  
Captcha Text Enter the text in the image.(Not Case sensitive)    



Spam Bot Trap



   



Select Theme
White
Gray
Blue
Brown
GraySimple