C#获取当前程序运行路径的几种方法
1. 获取模块的完整路径。 string path = System.Diagnostics.Process.GetCurrentProcess().
MainModule.FileName; Debug.Print(path); 输出:C:
\Users\Lenovo\Desktop\QRCode\QRCode\bin\Debug\QRCode.vshost.exe 2. 获取和设置当前目录(
该进程从中启动的目录)的完全限定目录 string path = System.Environment.CurrentDirectory; Debug.
Print(path); 输出:C:\Users\Lenovo\Desktop\QRCode\QRCode\bin\Debug 3. 获取应用程序的当前工作目录
string path = System.IO.Directory.GetCurrentDirectory(); Debug.Print(path); 输出:C
:\Users\Lenovo\Desktop\QRCode\QRCode\bin\Debug 4. 获取程序的基目录 string path = System.
AppDomain.CurrentDomain.BaseDirectory; Debug.Print(path); 输出:C:
\Users\Lenovo\Desktop\QRCode\QRCode\bin\Debug\ 5. 获取和设置包括该应用程序的目录的名称 string path
= System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase; Debug.Print(
path); 输出:C:\Users\Lenovo\Desktop\QRCode\QRCode\bin\Debug\ 6. 获取启动了应用程序的可执行文件的路径
string path = System.Windows.Forms.Application.StartupPath; Debug.Print(path);
输出:C:\Users\Lenovo\Desktop\QRCode\QRCode\bin\Debug 7. 获取启动了应用程序的可执行文件的路径及文件名
string path = System.Windows.Forms.Application.ExecutablePath; Debug.Print(path)
; 输出:C:\Users\Lenovo\Desktop\QRCode\QRCode\bin\Debug\QRCode.EXE 8
、获取当前进程的完整路径,包含文件名(进程名)。 string str = this.GetType().Assembly.Location; 结果:X:
\xxx\xxx\xxx.exe(.exe文件所在的目录+.exe文件名)

技术
今日推荐
PPT
阅读数 135
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信