未进入 if 条件时创建目录错误
本文关键字:创建目录 错误 条件 if | 更新日期: 2023-09-27 17:57:20
我在创建目录时遇到问题:
if (!Directory.Exists(directorypath)//here i have that problem not enter into if contion
{
Directory.CreateDirectory(directorypath);
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Successfully Saved');", true);
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Directory Already Exists');", true);
}
你能这样做吗?
try
{
if (!Directory.Exists(directorypath))
{
Directory.CreateDirectory(directorypath);
ClientScript.RegisterStartupScript(this,this.GetType(), "alert", "alert('Successfully Saved');", true);
}
else
{
ClientScript.RegisterStartupScript(this,this.GetType(), "alert", "alert('Directory Already Exists');", true);
}
}
catch(Exception ex)
{
throw;
}
我相信您对第一行的括号有问题,请确保directorypath
具有有效的路径