I have this code
FileStream fs = new FileStream("Scores.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.Write("Name: " + name_box.Text + " Time " + label1.Text);
sw.Close();
which is simple the label1 is assgined to a Timer tick as in the folowing
private void timer1_Tick(object sender, EventArgs e)
{
// Format and display the TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
label1.Text = elapsedTime;
}
now when I open the Text File I found the following results
Name: Tony Time 00:00:06.67Text: Time [System.Windows.Forms.Timer], Interval: 100
which are perfect but what is ( Text: Time [System.Windows.Forms.Timer], Interval: 100)
I don’t want that to appear in the txt
thanx in advance
You are using
FileMode.OpenOrCreatein the constructor. This does not erase the previous contents of the file. I suspect that if you delete the file and then try running your program again, you won’t see any of that extra stuff.I suggest either using
FileMode.CreateorFileMode.Append. Use the first if you want to overwrite the results, the second if you want to… well, append.