Newbie Needs to read entire text file, display it to a textBox, be able to edit the text box and save any changes to same text file

Posted on 2005-03-23
Medium Priority
Last Modified: 2010-04-23
I am very new at programming.
I am creating an app and need help on a couple of things.
I need to be able to read an entire already existing text file and display it in a textBox.
In this same textBox I need to be able to edit whats in the textBox and save it back to the original text file.
Any help would be appreciative.
Question by:jettman26
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 14

Expert Comment

ID: 13618724
This link has all the examples of creating(in your case, you don't need to create), reading, writing a text file:
LVL 14

Expert Comment

ID: 13618753

Assisted Solution

Anil_Poonia earned 500 total points
ID: 13619155
Hi jettman26

Try this one

Private Sub SaveToFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToFile.Click
        Dim Write As String
        Dim sw As New StreamWriter("c:\my.txt", False)
        Write = Trim(RichTextBox1.Text)
        RichTextBox1.Text = ""
    End Sub

    Private Sub ReadFrmFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReadFrmFile.Click
        Dim read As String
        Dim sr As New StreamReader("c:\my.txt")
        RichTextBox1.Text = sr.ReadToEnd

    End Sub

With Refards

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 13619167
Before use this code pls use following line

Imports System.IO

LVL 19

Accepted Solution

Fahad Mukhtar earned 500 total points
ID: 13620184
use a RichtextBox Control, then you can use the builtin LoadFile() and SaveFile Methods for your problem:

'1 line code to Load a text file in Rich TextBox
RichTextBox1.LoadFile("C:\New Text Document.txt", RichTextBoxStreamType.PlainText)

'1 line code to save the same text file from Rich TextBox
RichTextBox1.SaveFile("C:\New Text Document.txt", RichTextBoxStreamType.PlainText)
LVL 27

Expert Comment

ID: 13621192

Here is where I found good examples for getting started in VB.Net


Link for ASP programs...


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question