Accepting user input and writing it to a text file
-
Hi friends, I've a textbox and a button in my WinForm. Now, I want that, whatever the user enters in the textbox and clicks on the button, the entered text should be copied to a precreated text file "C:\test.txt". Note, that I am using Visual C# for this purpose. I searched google and MSDN, but my search ended up in futile. Please help me out with the appropriate code. Hope to hear from you guys soon, Rajdeep.NET :)
-
Hi friends, I've a textbox and a button in my WinForm. Now, I want that, whatever the user enters in the textbox and clicks on the button, the entered text should be copied to a precreated text file "C:\test.txt". Note, that I am using Visual C# for this purpose. I searched google and MSDN, but my search ended up in futile. Please help me out with the appropriate code. Hope to hear from you guys soon, Rajdeep.NET :)
You're joking, right? You couldn't find a result for "how do I append text to a file in C#[^]"?? I guarantee you'll find tons of results with that search.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Hi friends, I've a textbox and a button in my WinForm. Now, I want that, whatever the user enters in the textbox and clicks on the button, the entered text should be copied to a precreated text file "C:\test.txt". Note, that I am using Visual C# for this purpose. I searched google and MSDN, but my search ended up in futile. Please help me out with the appropriate code. Hope to hear from you guys soon, Rajdeep.NET :)
Well I can give you simple idea. I provide you source code you need to modify it. I am having some problem with my computer else I will do that proper code for you . just post you some my old exercise . just put this function on the button click I mean where you want it will save . If you want to save automaticaly you just modify . private void savingtext() { SaveFileDialog savetx = new SaveFileDialog(); savetx.DefaultExt = "rtf"; savetx.Filter = "Texto enrriquecido (*.rtf)|*.rtf"; savetx.FileName = "Log.rtf"; if (savetx.ShowDialog() == Windows.Forms.DialogResult.OK) { textbox1.text.SaveFile(savetx.FileName); } } Wisht it will help you
-
Hi friends, I've a textbox and a button in my WinForm. Now, I want that, whatever the user enters in the textbox and clicks on the button, the entered text should be copied to a precreated text file "C:\test.txt". Note, that I am using Visual C# for this purpose. I searched google and MSDN, but my search ended up in futile. Please help me out with the appropriate code. Hope to hear from you guys soon, Rajdeep.NET :)
I'm sorry, but I just cannot believe how many people have asked the same question on so many different forums. There ARE MANY SOLUTIONS to your problem at hand that can be obtained from a Google search. And by many, I mean thousands of solutions. Here is the code. I'm only doing this because I'm in a good mood today. Any other time, you'd be ^h%t out of luck. Double-click on your button that you've added to the form and inside the event handler type:
File.AppendAllText(@"C:\Test.txt", textBox1.Text);
..That is ofcourse, assuming your TextBox control's design name is still textBox1. Now, for this to work you need to include a 'using directive' in the top of your file like so:
using System.IO;
Hope this helps. Jason.