Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi dear THE CODE PROJECT members :
I have a probelm when writting in a text file i have a string
of 14 numbers and they change evey time with a space between them but the probelm every time it erase the previous line and write a new one until i find only the last line in the text file :( plz help me)
the code :
string path = @"D:\newS_R.txt";
     
                    TextWriter tw = new StreamWriter(path);
                    tw.WriteLine(textBox46.Text + " " + textBox45.Text + " " + textBox44.Text + " " + textBox43.Text + " " + textBox42.Text + " " + textBox41.Text + " " + textBox40.Text + " " + textBox39.Text + " " + textBox38.Text + " " + textBox37.Text + " " + textBox33.Text + " " + textBox34.Text + " " + textBox35.Text + " " + textBox36.Text + "" + Environment.NewLine);
                    tw.Close();
Posted
Comments
parmar_punit 18-Jun-11 9:10am    
see my solution no.4 it will help you more...

 
Share this answer
 
v2
Comments
omegarios 18-Jun-11 7:37am    
i have try it but it doesn't work :( thanks a lot for answring
You create a new file every time, try using this form[^] and append your data each time round. You should also consider using more meaningful field names in your code as the ones in your sample above will give you nightmares in the future maintenance of your code.
 
Share this answer
 
Comments
omegarios 18-Jun-11 7:45am    
thanks i didn't get the answer i'm so sorry i'm beginner in C#
Richard MacCutchan 18-Jun-11 8:01am    
Do you mean you cannot understand what I wrote, or you cannot understand the information in the link I posted?
omegarios 18-Jun-11 8:31am    
yeah the method how i can use it here !!
omegarios 18-Jun-11 8:34am    
ok i have 14 textboxes change it's values every 50 milisecond i want to write all this value as a coulum and when changing they must jum to a new line so the textfile will contain as a from of a matrix (14*3500) thanks a lot for your help
Richard MacCutchan 18-Jun-11 8:57am    
Go and look at the link I posted, you need to open your file with "append = true", to ensure that each line of data gets added to the end of the file, rather than overwriting the existing information, thus:
TextWriter tw = new StreamWriter(path, true);
This code will surely help you....

C#
string path = @"D:\newS_R.txt";
using(StreamWriter sw = new StreamWriter(path,true))
{
     sw.WriteLine(textBox46.Text + " " + textBox45.Text + " " + textBox44.Text + " " + textBox43.Text + " " + textBox42.Text + " " + textBox41.Text + " " + textBox40.Text + " " + textBox39.Text + " " + textBox38.Text + " " + textBox37.Text + " " + textBox33.Text + " " + textBox34.Text + " " + textBox35.Text + " " + textBox36.Text + "" + Environment.NewLine);
}
 
Share this answer
 
Comments
parmar_punit 18-Jun-11 9:11am    
Don't forget to upvoted and accept answer if you fill it usefull...
thanks & regards,
Punit
omegarios 18-Jun-11 9:37am    
Thanks so so so so much my friend it add new space but it work coreectly to so much :)
parmar_punit 22-Jun-11 7:38am    
Thanks, if it is really helpful to you, don't forget to vote it up.... :-)

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