Results 1 to 3 of 3

Thread: Open file !?

  1. #1

    Thread Starter
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    Talking Open file !?

    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 :-)!
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    The openfile dialog only gets the path it doesn't load the file for you. Try something like this:
    VB Code:
    1. 'this loads all the contents of the test.txt file in the application folder
    2.         'opens the file as a stream
    3.         Dim fs As New IO.FileStream("test.txt", IO.FileMode.Open)
    4.         'adds a reader to read from the stream
    5.         Dim sr As New IO.StreamReader(fs)
    6.         'reads all the data in the stream/file into the string variable
    7.         Dim contents As String = sr.ReadToEnd
    8.         'close the file very important
    9.         fs.Close()
    10.         'this is just to show you that the data is loaded
    11.         MsgBox(contents.ToString)
    Last edited by Edneeis; Feb 22nd, 2003 at 03:54 PM.

  3. #3

    Thread Starter
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    Thanks!!

    wow, makes sence with the comments

    Thanks!!

    Cheers !
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width