Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
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 18:28pm
Sergey Alexandrovich Kryukov at 31-Jan-13 23:31pm
How about just reading help more thoroughly? :-)
Luiey Ichigo at 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 at 31-Jan-13 23:54pm
OK, did you read my answer? This is all you need. 100% a solution...
Luiey Ichigo at 31-Jan-13 23:56pm
Yeah sir..I'll look forward on it
Sergey Alexandrovich Kryukov at 1-Feb-13 0:07am
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 at 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
Sergey Alexandrovich Kryukov at 1-Feb-13 1:40am
Did you really read the help pages?
If Boolean parameter "append" is false, the file is cleared; new content is written from scratch.
Sergey Alexandrovich Kryukov at 1-Feb-13 1:41am
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...
Luiey Ichigo at 1-Feb-13 2:00am
Lemme try first with a simple program..then I'll feedback you..
Luiey Ichigo at 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")
Sergey Alexandrovich Kryukov at 1-Feb-13 2:28am
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...

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
0 Zoltán Zörgő 185
1 Sergey Alexandrovich Kryukov 160
2 Peter Leow 100
3 CPallini 70
4 Ramza360 51
0 Zoltán Zörgő 80
1 the other paul 23
2 Shmuel Zang 10
3 Aarti Meswania 5
4 Member 11389991 -2

Advertise | Privacy | Mobile
Web04 | 2.8.150129.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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