Click here to Skip to main content
13,591,259 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi all,

Right now I'm able to read the textfile line by line until end of are the code

Dim Reader As StreamReader = File.OpenText("C:\Test.txt")
Dim FileText As String = Reader.ReadToEnd()
txtTest.Text = FileText

after it read all line, user able to edit the line and save the new data. But how can I clean the content of the textfile before I write the new data on it? I try to search on google but not find the right solution. So could someone help me on this?
I dont want to delete the file and create new one. I want to use the current textfile know what I mean. Please advise me on this
Posted 31-Jan-13 17:28pm
Sergey Alexandrovich Kryukov 31-Jan-13 23:31pm
How about just reading help more thoroughly? :-)
Luiey Ichigo 31-Jan-13 23:43pm
haha..I'll try to read first and feedback to you what I'm see through the page..tq
Sergey Alexandrovich Kryukov 31-Jan-13 23:54pm
OK, did you read my answer? This is all you need. 100% a solution...
Very good. When and if you see it makes sense, please accept the answer formally (green button), if not, ask what's not clear, I'll gladly answer.
Luiey Ichigo 1-Feb-13 1:35am
Sir, I've seen through the page. But I can't even see the code how to clean all content on current textfile. Let's say the textfile content a text with this:

Please refer to nearest counter
for further assistance

This line of code is for example the current text on the textfile. If I want to edit the thing using my program (use for Support Engineer if there any changes on this) to:

If you have any inquiry
please call 1-800-8585

So this is what I mean. I'm glad for your assistance sir
Luiey Ichigo 31-Jan-13 23:56pm
Yeah sir..I'll look forward on it
Did you really read the help pages?
If Boolean parameter "append" is false, the file is cleared; new content is written from scratch.
I don't know, may be you also did not understand that the reader is only for reading. You should close it, and use writer to write the new data...
Oh, great. And you found it by yourself: I forget to mention that no Boolean parameter defaults to "append = false", so it really re-writes the file, too.

You are welcome.
Good luck, call again...
Luiey Ichigo 1-Feb-13 2:00am
Lemme try first with a simple program..then I'll feedback you..
Luiey Ichigo 1-Feb-13 2:25am
Sir, thank you for your assistance. I've found the way from the page,this is the way I use:

Dim Reader As StreamWriter
Reader = New StreamWriter("C:\Test.txt")

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Look here:[^].

Now, locate the section "Constructors". Look through the help pages for the constructors, but only those having a Boolean parameter. Read about this parameter in any of those page. This parameter is your solution.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web04-2016 | 2.8.180618.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100