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
Share:
16,104

Related videos on Youtube

user3657339
Author by

user3657339

Updated on June 22, 2022

Comments

  • user3657339
    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
    user3657339 almost 10 years
    I need to write this in C# and this System.DateTime.Now.ToString("yyyyMMdd") will be a variable. Can you help.
  • PKirby
    PKirby over 8 years
    Can you please provide a brief explanation.
  • John
    John over 2 years
    this should be DateTime.Now.ToString("ddMMyyyyHHmm") otherwise it will give you minutes, not months :)

Related