|
-
Dec 15th, 2011, 08:49 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Add text to txt file from texbox
I already know how add text but my problem is add a new line without remove the others lines. for example
textbox1="text1"
When I press a button I want to add "text1" into the txt file
textbox1="text2"
When I press a button I want to add "text2" and keep "Text1" into the txt file:
text1
text2
Can you help me?
-
Dec 15th, 2011, 09:38 PM
#2
Re: Add text to txt file from texbox
You have two choices. Under the hood they will do pretty much exactly the same thing but the code you write will change a little.
First, you can create a StreamWiter. The constructor provides an option to specify whether to overwrite existing data or append. You can then call WriteLine and/or Write, depending on whether you want the file to end with a line break or you want to write the line break before each new bit of text.
Second, you can call File.AppendAllText. In that case you would provide a String to write that ended with a line break, which you would add using Environment.NewLine.
-
Dec 15th, 2011, 10:45 PM
#3
Thread Starter
Hyperactive Member
Re: Add text to txt file from texbox
Ok I have this code
Dim W As New IO.StreamWriter("C:\created.txt")
W.Write(TextBox1.Text)
W.Close()
But this code overwrite son I need append the txt but I don't know how.
-
Dec 15th, 2011, 10:58 PM
#4
Re: Add text to txt file from texbox
As I said, the StreamWriter constructor provides the option to specify whether to overwrite or append. The logical thing to do is to consult the MSDN documentation for the StreamWriter constructor to see what that option is and how to use it. Whenever you have the name of a type and/or member and you need information about it, the first thing you do should be to read the relevant documentation.
-
Dec 15th, 2011, 11:54 PM
#5
Re: Add text to txt file from texbox
There's also the appending boolean value for a secondary parameter in StreamWriter
Code:
StreamWriter("File.txt", True)
True would tell it that append is acceptable as a boolean value (True) of course. Non tested, but from what I can remember it's as easy as that.
<<<------------
.NET Programming (2012 - 2018)
®Crestron - DMC-T Certified Programmer | Software Developer <<<------------
-
Dec 16th, 2011, 12:09 AM
#6
Re: Add text to txt file from texbox
 Originally Posted by AceInfinity
There's also the appending boolean value for a secondary parameter in StreamWriter
It's not "also" because that's exactly what I was talking about. Now that you have deprived the OP of the need to consult the documentation, the next time a similar issue arises, they will likely have to post again rather than being able to consult the documentation and solve the issue for themselves. @romanos8, hopefully you will still take a look at the documentation so you can see how easy it can be to solve a lot of your own problems.
-
Dec 16th, 2011, 12:40 AM
#7
Thread Starter
Hyperactive Member
Re: Add text to txt file from texbox
Thanks I already fix the problem.
-
Dec 18th, 2011, 11:41 PM
#8
Re: Add text to txt file from texbox
 Originally Posted by jmcilhinney
It's not "also" because that's exactly what I was talking about. Now that you have deprived the OP of the need to consult the documentation, the next time a similar issue arises, they will likely have to post again rather than being able to consult the documentation and solve the issue for themselves. @romanos8, hopefully you will still take a look at the documentation so you can see how easy it can be to solve a lot of your own problems.
I didn't realize it was a game to get him to go read the documentation. Although good for him to read documentation just like any other information available in a standard documentation, it does leave this forum with less activity, until there's people that don't understand documentation, and have to resort to further alternatives. I was only trying to help, so thanks for seeing that side of the equation.
<<<------------
.NET Programming (2012 - 2018)
®Crestron - DMC-T Certified Programmer | Software Developer <<<------------
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|