Trying to include date into a filename when the file is written.
DateTime todaysDate = DateTime.Now;
string destFile = System.IO.Path.Combine(targetPath + todaysDate.ToShortDateString() + ".dat");
Error:
Could not find a part of the path 'C:\Users\John\Desktop\Sales\Import11/02/2014.dat'.
Possible to change date to separated by _ ? or any other suggestions to resolve this? Ta
I would suggest:
/
and :
do)So something like:
string name = string.Format(CultureInfo.InvariantCulture,
"Import-{0:yyyy-MM-dd}.dat",
DateTime.Today);
// Assuming that targetPath is the directory; it's slightly unclear.
string path = Path.Combine(targetPath, name);
Note:
Today
, you're using the system local time zone. That may well be what you want, but you need to consider it explicitly.See more on this question at Stackoverflow