Use
DateTime.Now
to get the current timestamp, then call
.ToString
on it with the date format you want (for example,
yyyy-MM-dd-HH-mm-ss
which is
year-month-day-hour-minute-second
) and put that in your file name. Also, if you use a verbatim string literal (with
@
), you don't have to escape the backslashes.
System.IO.File.AppendAllText(string.Format(@"C:\izaz\{0}.txt", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")), "text to append");