c# - 在C#项目中动态创建文件夹

标签 c# .net winforms

我必须在 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/

相关文章:

c# - C# 中完整的老式 TUI 命令行应用程序

.net - C# 中的 Settings.settings 用于连接字符串

.net - 单元测试用户界面。什么是有效的方法?

c# - 在静态类中保存对记录器的引用

c# - WPF:在 XAML 中设置 ItemSsource 与代码隐藏

c# - 弹道库

c# - 重复代码位的设计模式/C#技巧

c# - ReportViewer - Windows XP 上的 System.IO.FileNotFoundException

c# - 无法通过c#删除.exe文件

c# - 单声道 C# 教程?