How would I get it to add the File Creation time to my .txt name?

54 Views Asked by At

I am creating multiple .txt files for my DataGridView and I wanted to add a creation date to them. *****EDIT***** I have changed my code to the following to see if it would output a time stamp:

private void button2_Click(object sender, EventArgs e)
{
    DateTime timenow = new DateTime();
    DateTime.Now.ToString("yyyyddhh");
    Console.WriteLine(timenow.ToString());

    string LPath = Path.Combine(path, Path.GetRandomFileName() + ".txt");

    using (StreamWriter objWriter = new StreamWriter(LPath, true))
    {
        string LContent = textName.Text + "," + textVehicle.Text + "," + textDurationH.Text + " " + textDurationM.Text + "," + textFreight.Text + "," + textWeight.Text + "," + textIncome.Text + "," + LPath;
        objWriter.Write(LContent);
        infoTabelle.Rows.Add(LContent.Split(','));
        objWriter.WriteLine();
    }
    replace();
}

But it just outputs 01.01.0001 00:00:00. What do I have to do? :/


I have tried using various DateTime commands but none have seemed to work for me. Any help is appreciated!

1

There are 1 best solutions below

3
On BEST ANSWER

Try

DateTime timenow = DateTime.Now;

instead of

DateTime timenow = new DateTime();

Then add it to your filename string.