zimcoder Level: VB Lord

 Registered: 27-10-2003 Posts: 225
|
Re: Reading a File
This may not fully address your problem but i trust it will point you in the right direction.
to do file input and output in vb.net you need to import the necessary namespace :
Imports System.IO
you will need to create an instance of the StreamReader class
one of the StreamReader constructors takes the file path as its argument :
Dim sr as StreamReader
sr = New StreamReader("\\path")
you must put this in a try catch block to catch all the likely errors and exceptions such as FileNotFoundException ..etc
here are the essential sections of the sample code that i have written:
'include the namspace
Imports System.IO
'declare the StreamReader Instance
Dim sr as StreamReader
'the variables
Friend WithEvents txtFilePath As System.Windows.Forms.TextBox
Friend WithEvents lblFilePath As System.Windows.Forms.Label
Friend WithEvents txtReadText As System.Windows.Forms.TextBox
Friend WithEvents btnReadFile As System.Windows.Forms.Button
'the sub that does all the work
Private Sub btnReadFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadFile.Click
If txtFilePath.Text = Nothing Then
MessageBox.Show("Please enter a file path name", "Warning")
Else
Try
sr = New StreamReader(txtFilePath.Text)
Dim strtext As String = sr.ReadToEnd()
txtReadText.Text = strtext
sr.Close()
Catch ex As FileNotFoundException
MessageBox.Show("File was Not Found", "Warning")
End Try
End If
End Sub
if you are dealing with TCP/IP streams then you will have to use the stream class that comes within the same nasmepace, System.IO. this allows you to read streams of data as bytes across the network. hope this will start you off in the right direction
____________________________
BrainBench ADO.NET and ASP.NET Certified Developer
 
|