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	est	est5WindowsFormsApp1WindowsFormsApp1inDebug
12             string binpath = debugpath.Substring(0, debugpath.LastIndexOf("\"));
13             // binpath: F:C#_Project	est	est5WindowsFormsApp1WindowsFormsApp1in
14             string dbpath = binpath.Substring(0, binpath.LastIndexOf("\"));
15             // dbpath: F:C#_Project	est	est5WindowsFormsApp1WindowsFormsApp1
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

原文地址:https://www.cnblogs.com/uhanhi/p/12968606.html