C#获取工作目录

 1 using System.Windows.Forms; // 添加库
 2 
 3 namespace WindowsFormsApp1
 4 {
 5     class DBHelper
 6     {
 7         public static void getDebugpath()
 8         {
 9             // 获取Debug的路径
10             string debugpath = Application.StartupPath;
11             // debugpath: F:\C#_Project\test\test5\WindowsFormsApp1\WindowsFormsApp1\bin\Debug
12             string binpath = debugpath.Substring(0, debugpath.LastIndexOf("\\"));
13             // binpath: F:\C#_Project\test\test5\WindowsFormsApp1\WindowsFormsApp1\bin
14             string dbpath = binpath.Substring(0, binpath.LastIndexOf("\\"));
15             // dbpath: F:\C#_Project\test\test5\WindowsFormsApp1\WindowsFormsApp1
16             Console.WriteLine("debugpath: " + debugpath);
17             Console.WriteLine("binpath: " + binpath);
18             Console.WriteLine("dbpath: " + dbpath);
19         }
20         static void Main(string[] args)
21         {
22             GetConnection();
23         }
24     }
25  
26 }

使用System.Windows.Forms中的Application.StartupPath

C#获取工作目录

上一篇:linux系统安装docker


下一篇:WPF学习笔记-图形