Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

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

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.
0
jettman26
Asked:
jettman26
2 Solutions
 
amyhxuCommented:
This link has all the examples of creating(in your case, you don't need to create), reading, writing a text file:
http://www.builderau.com.au/program/windows/0,39024644,20267367,00.htm
0
 
amyhxuCommented:
0
 
Anil_PooniaCommented:
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)
        sw.WriteLine(Write)
        sw.Close()
        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

        sr.Close()
    End Sub


With Refards

Anil
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Anil_PooniaCommented:
Before use this code pls use following line

Imports System.IO

0
 
Fahad MukhtarDistinguished EngineerCommented:
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)
0
 
planoczCommented:
Hi,

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

.....http://msdn.microsoft.com/vbasic/downloads/samples/101samples.aspx

Link for ASP programs...

http://msdn.microsoft.com/asp.net/downloads/kits/default.aspx 
0

Featured Post

Industry Leaders: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now