Results 1 to 3 of 3

Thread: File reading in vb.net

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2003
    Posts
    5

    File reading in vb.net

    I want to append (concatenate) a string to each line in a text file.
    My program should work like this.
    Suppose I give the text file name in one textbox(the file may be present anywhere in the computer)
    and in the other textbox if I give the string.

    Now when I click a button, the resultant file(new file with appended string), should be stored again.

    Please tell me how to get the file in the textbox from a dialog box.

    Also can anyone supply some sample code for this file reading?

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    VB Code:
    1. Dim strmWriter as System.IO.StreamWriter = New System.IO.StreamWriter(filename,True) ' True tells it to append. If false, it overwrites
    2.  
    3. strmWriter.Writeline(text_to_add)

    Easy as pie.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    And in related information for future reference. Reading a file

    VB Code:
    1. Dim filestream as System.IO.StreamReader= New System.IO.StreamReader(Filename)
    2. Dim FileLine as String
    3.  
    4. Do Until filestream.Peek = -1
    5.       FileLine = filestream.ReadLine()
    6. Loop
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

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