Claude Hitech
Claude Hitech

Reputation: 13

C# how to create a log file from multiple textboxes?

Initially the idea was to create a simple empty file containing only the date it was created. But now I need to create a log file with the contents of 2 different textBoxes (textBoxName and textBoxPhone). Below is the code I have so far, only to create an empty log file with the date/time stamp in its filename:

string myFileName = String.Format ("(0). (1)", DateTime. Now. ToString("yyyy Mddhhnnss"), "log");
string myFullPath = Path.Combine("D: \\", myFileName);
using (StreamWriter sw = File.CreateText (myFullPath))
{
sw.WriteLine(sw);
}

Thanks a lot.

Upvotes: 0

Views: 51

Answers (1)

Carsten.R
Carsten.R

Reputation: 128

Hi please take a close look at the adjustments I made.

string myFileName = String.Format("{0}.{1}", DateTime.Now.ToString("yyyyMMddhhmmss"), "log");
string myFullPath = Path.Combine(@"C:\temp", myFileName);
using (StreamWriter sw = File.CreateText(myFullPath))
{
       string content = String.Format("{0};{1}", textBox1.Text, textBox2.Text);
       sw.WriteLine(content);
}

Upvotes: 1

Related Questions