我必须在 C#
项目中动态创建一个文件夹并向其中添加文件。
尝试了下面的代码,但它在 bin
文件夹中创建了文件夹。我需要在项目运行路径本身中创建。
//代码:
// Specify a name for your top-level folder.
string folderName = @"..\Top-Level Folder";
System.IO.Directory.CreateDirectory(folderName);
我哪里错了?
最佳答案
我猜你正在找这个
string projectPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
string folderName = Path.Combine(projectPath, "Top-Level Folder");
System.IO.Directory.CreateDirectory(folderName);
关于c# - 在C#项目中动态创建文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22475505/