PDA

Click to See Complete Forum and Search --> : Open file !?


vbNeo
Feb 21st, 2003, 07:40 PM
I'm trying out VB.Net, which is actually very cool!
I've been playing a bit around with it, but i'm not quite sure on how to open a file and load it into a string.
I just OpenFileDialog.OpenFile to load the file... And i THINK it is loaded, i just don't know how to get it into the textbox, please help :-)!

Edneeis
Feb 21st, 2003, 07:54 PM
The openfile dialog only gets the path it doesn't load the file for you. Try something like this:

'this loads all the contents of the test.txt file in the application folder
'opens the file as a stream
Dim fs As New IO.FileStream("test.txt", IO.FileMode.Open)
'adds a reader to read from the stream
Dim sr As New IO.StreamReader(fs)
'reads all the data in the stream/file into the string variable
Dim contents As String = sr.ReadToEnd
'close the file very important
fs.Close()
'this is just to show you that the data is loaded
MsgBox(contents.ToString)

vbNeo
Feb 22nd, 2003, 05:43 AM
wow, makes sence with the comments :)

Thanks!!

Cheers !