C#获取当前路径的方法如下:
(1)string path1 = System.Environment.CurrentDirectory;
//C:\...\bin\Debug
-获取和设置当前工作目录(该进程从中启动的目录)的完全限定目录。
(2)string path2 =
System.IO.Directory.GetCurrentDirectory();
//C:\...\bin\Debug
-获取应用程序的当前工作目录。网上说这个方法得到的不一定是程序从中启动的目录,我试的和(1)的结果一样,证明有时得到的还是程序从中启动的目录。
(3)string path3 =
System.Windows.Forms.Application.StartupPath;
//C:\...\bin\Debug
-获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。
(4)string path4 =
System.AppDomain.CurrentDomain.BaseDirectory;
//C:\...\bin\Debug\
-获取基目录,它由程序集冲突解决程序用来探测程序集。
(5)string path5 =
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
//C:\...\bin\Debug\
-获取或设置包含该应用程序的目录的名称。
(6)string path6 =
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
//C:\...\bin\Debug\WindowsFormsApplication1.vshost.exe
-获取模块的完整路径。
()7string path7 =
System.Windows.Forms.Application.ExecutablePath;
//C:\...\bin\Debug\WindowsFormsApplication1.EXE
-获取启动了应用程序的可执行文件的路径,包括可执行文件的名称。
当前路径与相对路径的合并:
string path8
= System.IO.Path.GetFullPath(System.IO.Path.Combine(path1,
@"..\..\obj\x86\Debug"));
string[] array =
System.IO.Directory.GetFiles(path8);
C#获取当前路径,获取当前路径的上一层路径,布布扣,bubuko.com
原文:http://www.cnblogs.com/diyishijian/p/3690194.html