Click here to Skip to main content
12,510,985 members (56,904 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
Hi all,

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

Dim Reader As StreamReader = File.OpenText("C:\Test.txt")
Dim FileText As String = Reader.ReadToEnd()
Reader.Close()
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 and..you know what I mean. Please advise me on this
Posted 31-Jan-13 17:28pm
Comments
Sergey Alexandrovich Kryukov 31-Jan-13 23:31pm
   
How about just reading help more thoroughly? :-)
—SA
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...
—SA
Luiey Ichigo 31-Jan-13 23:56pm
   
Yeah sir..I'll look forward on it
   
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.
—SA
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
   
Did you really read the help pages?
If Boolean parameter "append" is false, the file is cleared; new content is written from scratch.
—SA
   
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...
—SA
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")
Reader.Write(TextBox1.Text)
Reader.Close()
   
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...
—SA

1 solution

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

Solution 1

Look here: http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx[^].

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.

—SA
  Permalink  

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 | Mobile
Web01 | 2.8.160929.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2016
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