在下面的代码中,我想在asp.net中创建2个子文件夹。我已经尝试了以下代码,但它不是创建子文件夹。请帮我这样做。
string Uploadpath = ConfigurationManager.AppSettings["FilePath"];
string sBatchName = System.DateTime.Now.ToString("ddMMMyyyyhhmmss");
string[] sFolder = new string[3];
sFolder[0] = "\\Input\\";
sFolder[1] = "\\Data\\";
string strUploadpath = Uploadpath.TrimEnd("\\".ToCharArray()) + "\\" + sBatchName + "\\";
DirectoryInfo dInfo = new DirectoryInfo(strUploadpath);
if (!dInfo.Exists)
{
dInfo.Create();
}
for (int i = 0; i < sFolder.Length; i++)
{
DirectoryInfo info = new DirectoryInfo(strUploadpath + sFolder[i]);
if (!dInfo.Exists)
{
dInfo.Create();
}
}
答案 0 :(得分:1)
for (int i = 0; i < sFolder.Length; i++)
{
DirectoryInfo info = new DirectoryInfo(strUploadpath + sFolder[i]);
if (!info .Exists)
{
info.Create();
}
}
您应该使用info
对象而不是dInfo
。
答案 1 :(得分:0)
您可以使用
创建SubDirectory
Directory.CreateDirectory(path);
其中path
是current directory