使用值作为名称创建子文件夹

Create a subfolder using value as name

我正在使用下一个代码在我的项目路径中创建一个文件夹

 string projectPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
 string folderName = Path.Combine(projectPath, "images");
 System.IO.Directory.CreateDirectory(folderName);

它创建了一个文件夹 image ...现在我想创建一个子文件夹,它的名字取自我表单中的文本框值。每次更改值时都会创建一个新的子文件夹新值作为名称

例如,如果我的表单有一个值为 56 的文本框,那么我想在其中创建一个文件夹 image,一个名为 56 的子文件夹,因此路径将是...\image

如果值更改为 48,则使用子文件夹 ...\image 创建新文件夹 ... 等

您可以将名称与您的视图值结合起来,并在创建新文件夹之前测试它是否已经存在:

var myValueFromView = "56";
string projectPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
string folderName = Path.Combine(projectPath, "images", myValueFromView);
if(!System.IO.Directory.Exists(folderName))
    System.IO.Directory.CreateDirectory(folderName);