Appending date in FileName - Vb.net
16,104
Solution 1
Chech below code
VB.Net
Dim FileName As String = "Events_Data.csv"
FileName = FileName.Replace(".csv", "_" & System.DateTime.Now.ToString("yyyyMMdd") & ".csv")
C#.Net
string FileName = "Events_Data.csv";
string ptest =System.DateTime.Now.ToString("yyyyMMdd");
FileName = FileName.Replace(".csv", "_" + ptest + ".csv");
Solution 2
Dim FileName As String = "Your File Name"
FileName += DateTime.Now.ToString("ddmmyyyyHHmm") + _
System.IO.Path.GetExtension(FileUpload1.FileName)
FileUpload1.SaveAs(Server.MapPath("Upload/" + FileName))
FileName = "Upload/" + FileName
Related videos on Youtube
Author by
user3657339
Updated on June 22, 2022Comments
-
user3657339 almost 2 years
I have got this
FileName = "Events_Data.csv"
I want to add date to this, so output required is
FileName = "Events_Data_20140521.csv"
I have got data in separate variables, just don't know how to add this before .csv in the file name.
Can anyone please help.
Regards
-
user3657339 almost 10 yearsI need to write this in C# and this System.DateTime.Now.ToString("yyyyMMdd") will be a variable. Can you help.
-
PKirby over 8 yearsCan you please provide a brief explanation.
-
John over 2 yearsthis should be DateTime.Now.ToString("ddMMyyyyHHmm") otherwise it will give you minutes, not months :)