string filename = DateTime.Today.ToString() + ".csv";
if(!File.Exists(filename))
File.Create(filename);
I thought this would work but it throws a ‘format not supported’ error. I just want a csv to be created in the directory alongside my .exe
This is because
DateTime.Today.ToString()contains slashes, which are not valid as part of a windows filename.You can, however, do this:
DateTime.Now.ToString("yyyyMMdd")