Hi,
How to make the excel file generate with date & Time?i have error as below. Thanks.
@balaraj.pubalan
: and / are not supported in file name.
DateTime.Now.ToString("MMddyyyy hhmmtt)
Hi,
In C#, as backslash is special character, it’s necessary to escape backslash or use @ as the following
"C:\\Users\Documents\\DL_"
OR
@"C:\Users\Documents\DL_"
In addition, / and : cannot be used as file name (or file path if you want to use it as part of directory name ). So as a result,the following will work, for example.
@"C:\Users\Documents\DL_" +DateTime.Now.ToString("MMddyyyy-hhmm tt")
Regards,
@balaraj.pubalan As mentioned by above responses, backslash \
and slash /
are illegal characters as part of filenames. I would just add that when working with dates in filenames the ISO 8601 format works best yyyy-MM-dd
It doesn’t use slashes, unambiguous and is an actual standard. This also has a positive effect of sorting your files chronologically (regardless of creation/access time properties) when sorted alphabetically.
Know more about why people should be using this format more: ISO - ISO 8601 — Date and time format
Thanks!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.