C#实现获取程序路径方法小结
本文实例讲述了C#实现获取程序路径方法。分享给大家供大家参考。具体如下:
获取DLL的目录:
AssemblymyAssembly=Assembly.GetEntryAssembly(); stringpath=myAssembly.Location; DirectoryInfodr=newDirectoryInfo(path); path=dr.Parent;//当前目录的上一级目录
C#获取程序当前路径的方法:
System.Environment.CurrentDirectory; //例:c:\test Application.ExecutablePath;(包括名称) //例:c:\test\myapp.exe Application.StartupPath;(不包括名称) //例:c:\test //获取新的Process组件并将其与当前活动的进程关联的主模块的完整路径,包含文件名(进程名)。 stringstr=System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; result:X:\xxx\xxx\xxx.exe(.exe文件所在的目录+.exe文件名) //获取和设置当前目录(即该进程从中启动的目录)的完全限定路径。 stringstr=System.Environment.CurrentDirectory; result:X:\xxx\xxx(.exe文件所在的目录) //获取当前Thread的当前应用程序域的基目录,它由程序集冲突解决程序用来探测程序集。 stringstr=System.AppDomain.CurrentDomain.BaseDirectory; result:X:\xxx\xxx\(.exe文件所在的目录+"\") //获取和设置包含该应用程序的目录的名称。 stringstr=System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase; result:X:\xxx\xxx\(.exe文件所在的目录+"\") //获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。 stringstr=System.Windows.Forms.Application.StartupPath; result:X:\xxx\xxx(.exe文件所在的目录) //获取启动了应用程序的可执行文件的路径,包括可执行文件的名称。 stringstr=System.Windows.Forms.Application.ExecutablePath; result:X:\xxx\xxx\xxx.exe(.exe文件所在的目录+.exe文件名) //获取应用程序的当前工作目录(不可靠)。 stringstr=System.IO.Directory.GetCurrentDirectory(); result:X:\xxx\xxx(.exe文件所在的目录)
获取系统特殊文件夹路径(收藏夹,桌面)
1.收藏夹路径
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Favorites)
2.桌面路径
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop)
希望本文所述对大家的C#程序设计有所帮助。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下