Question

I am trying to save file with text to specific location:

saveFileDialog.FileName = "Info_" + 
     System.DateTime.Now.ToString("yyyyMMddhmmss" + ".txt");
string Info = "";
TextFormat(ref Info);
File.WriteAllText(Path.Combine(dir.ToString(),saveFileDialog.FileName), Info);

so right now when I am pressing the button if gives me filename: Info_2013030114511.PxP (note ".PxP" instead of ".txt"), but if I will change to:

saveFileDialog.FileName = "Info_" +
   System.DateTime.Now.ToString("yyyyMMddhmmss" + ".TXT");

gives me correct result: Info_2013030114511.TXT

I am wondering if it's a bug or am I doing something wrong...

Était-ce utile?

La solution

You are supplying "yyyyMMddhmmss.txt" to the DateTime format function. It is interpreting the 't' as the a.m./p.m. specifier. What you mean to do is:

saveFileDialog.FileName = "Info_" + 
                          System.DateTime.Now.ToString("yyyyMMddhmmss") + ".txt";
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top