Windows Develop Bookmark and Share   
 index > Windows Forms General > File help!
 

File help!

Hi i would like to know how to read from a, lets say a txt file, read some lines that are in the txt file to put on textboxes... how do i read? any help? thank you
Cobaia  Monday, January 22, 2007 8:28 PM

Cabaia:

Here's a VB example of reading a file:

Imports System
Imports System.IO

Class Test
Public Shared Sub Main()
Try
' Create an instance of StreamReader to read from a file.
Using sr As StreamReader = New StreamReader("TestFile.txt")
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = sr.ReadLine()
Console.WriteLine(Line)
Loop Until line Is Nothing
sr.Close()
End Using
Catch E As Exception
' Let the user know what went wrong.
Console.WriteLine("The file could not be read:")
Console.WriteLine(E.Message)
End Try
End Sub
End Class

Alan Robbins  Monday, January 22, 2007 9:18 PM

Google is a great resource for questions like this. Check out this article:

"How to read from and write to a text file by using Visual C#"

http://support.microsoft.com/kb/816149

xr280xr  Monday, January 22, 2007 9:16 PM

Cabaia:

Here's a VB example of reading a file:

Imports System
Imports System.IO

Class Test
Public Shared Sub Main()
Try
' Create an instance of StreamReader to read from a file.
Using sr As StreamReader = New StreamReader("TestFile.txt")
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = sr.ReadLine()
Console.WriteLine(Line)
Loop Until line Is Nothing
sr.Close()
End Using
Catch E As Exception
' Let the user know what went wrong.
Console.WriteLine("The file could not be read:")
Console.WriteLine(E.Message)
End Try
End Sub
End Class

Alan Robbins  Monday, January 22, 2007 9:18 PM

You can use google to search for other answers

Custom Search

More Threads

• Try to fix dis
• Disable Windows XP Repair-Install Setup
• How Timer Works(Thread)
• Problems with RichtTextBox
• Focus on ListView/ListViewItem
• Drawing Rectangle Extremely Slow
• ActiveDocumentHost
• Textbox problem
• Maximize a form
• How do you call the business dlls