我想在global.asax中使用DateTime給文件的名稱,但它會給出錯誤。你能幫忙嗎?DateTime不工作在Global.asax在c#
我用於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;
}
它給了什麼錯誤? – M4N
你忘了在根目錄中使用路徑,即'ConfigurationManager.AppSettings [「LogFileFolder」]中的'〜/ yourpath'? –
它給出了什麼錯誤? –