asp.net - DateTime Not working in Global.asax in c# -
i trying use datetime in global.asax give name file gives error. please assist?
the code using datetime;
public void callfilecreate() {     string path = configurationmanager.appsettings["logfilefolder"].tostring();       string filename = httpcontext.current.server.mappath(path + "\\log_" + datetime.now.toshortdatestring().replace("/", ".") + "_" + (datetime.now.tolongtimestring()).replace(":", "_") + ".txt");     tracefilepath = httpcontext.current.server.mappath(path + "\\scheduler" + datetime.now.toshortdatestring().replace("/", ".") + "_" + (datetime.now.tolongtimestring()).replace(":", "_") + ".txt");     filestream fs = null, fs1 = null;     fs = file.create(filename);     fs1 = file.create(tracefilepath);     errorfilepath = filename; } 
you should use path class if work paths:
string path = configurationmanager.appsettings["logfilefolder"].tostring(); string filename = string.format("{0}_{1}_{2}.txt"     , "log"     , datetime.today.tostring("dd.mm.yyyy")  // change according actual culture     , datetime.now.tostring("hh_mm_ss")); string fullpath = path.combine(path, filename); not sure if solves issue, increases readability , avoids careless mistakes anyway.
Comments
Post a Comment