Click here to Skip to main content
15,918,178 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have 2 textboxes, and how can I type something in those two textboxes and info will append to csv file?

Thanks
Posted
Updated 21-Apr-11 4:27am
v2
Comments
Sandeep Mewara 21-Apr-11 10:28am    
Not clear - how tying into two textboxes lead to a CSV?

You have to do several things here:

1. Get the text of those textboxes. Two variables will do it.
2. Learn to open a file... look for "fopen, fwrite"... you'll find how to work with files easily.
3. Writing the contents to the file:
3.1. If you know the format and also know that nobody will modify the file by hand, then everything is really easy... simply add the text you want at the end of the file...
3.2. If you can't be sure that nobody will modify those files... well then it's time to create a parser and verify the integrity of the file before inserting text into it...

Those are the rough steps on how to do it...

Usually when programming you must divide the problem you are facing...

At least this is what I'd do...

Hope this helps...

With those directives... when you will find a problem (surely you will) please post back and someone here will help you.

Good luck!
 
Share this answer
 
Comments
Nish Nishant 21-Apr-11 11:07am    
Voted 5, and proposed as answer!
Joan M 21-Apr-11 11:13am    
Thank you Nish!
RaviRanjanKr 21-Apr-11 12:03pm    
Nice Answer! My 5
Joan M 21-Apr-11 12:06pm    
Thank you RaviRanjankr!
Here is my code:


private void AddBtn_Click(object sender, EventArgs e)
{
//create CSV file
string CSV_File = "C:\\test.csv";

System.IO.StreamWriter(CSV_File, true);
if (System.IO.File.Exists(CSV_File))
{
string FileHeader = ("First Name" + "," + "Last Name" + System.Environment.NewLine);
System.IO.File.WriteAllText(CSV_File, FileHeader);
}
string FileDeail = FirstTxt.Text + "," + LastTxt.Text;
System.IO.File.AppendAllText(CSV_File, FileDeail);
FirstTxt.Text = " ";
LastTxt.Text = " ";
{

However, when i type a new info into textboxes, the old information is deleted.

How to append the new info after the old info?

thanks,
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900