在没有进入if条件的情况下创建目录错误

时间:2015-06-19 11:35:54

标签: c#

我在创建目录时遇到问题:

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);
}

1 个答案:

答案 0 :(得分:0)

你能这样做吗?

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有有效路径