1.获取包含清单的已加载文件的路径或 UNC 位置
Assembly.GetExecutingAssembly().Location
this.GetType().Assembly.Location
result:
D:\project\JNJ\JNJ\Test\test\bin\Debug\My.Test.exe
2.获取新的 Process 组件并将其与当前活动的进程关联的主模块的完整路径,包含文件名(进程名)
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
result:
D:\project\JNJ\JNJ\Test\test\bin\Debug\My.Test.vshost.exe
3.获取和设置当前目录(即该进程从中启动的目录)的完全限定路径。
System.Environment.CurrentDirectory
result:
D:\project\JNJ\JNJ\Test\test\bin\Debug
4.当前文件路径
//D:\project\JNJ\JNJ\Test\test\bin\Debug
string path = System.Environment.CurrentDirectory;
//D:\project\JNJ\JNJ\Test\test\bin
string path2 = path.Substring(0,path.LastIndexOf("\\"));
//D:\project\JNJ\JNJ\Test\test
string path3 = path2.Substring(0, path2.LastIndexOf("\\"));
5.获取当前 Thread 的当前应用程序域的基目录,它由程序集冲突解决程序用来探测程序集。
System.AppDomain.CurrentDomain.BaseDirectory
获取和设置包含该应用程序的目录的名称
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。
System.Windows.Forms.Application.StartupPath
result:
D:\project\JNJ\JNJ\Test\test\bin\Debug\
6.获取启动了应用程序的可执行文件的路径,包括可执行文件的名称。
System.Windows.Forms.Application.ExecutablePath
result:
D:\project\JNJ\JNJ\Test\test\bin\Debug\My.Test.EXE
7.相对路径,我们可以使用Path.GetFullPath方法获得它的完
Path.GetFullPath("../../image/")
result:
D:\project\JNJ\JNJ\Test\test\image\