C# 获取当前路径7种方法
C# 获取当前路径7种方法
2013年12月11日 15:43:16 liudong8510 阅读数 20558
-
//获取模块的完整路径。
-
string path1 = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
-
//获取和设置当前目录(该进程从中启动的目录)的完全限定目录
-
string path2 = System.Environment.CurrentDirectory;
-
//获取应用程序的当前工作目录
-
string path3 = System.IO.Directory.GetCurrentDirectory();
-
//获取程序的基目录
-
string path4 = System.AppDomain.CurrentDomain.BaseDirectory;
-
//获取和设置包括该应用程序的目录的名称
-
string path5 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
-
//获取启动了应用程序的可执行文件的路径
-
string path6 = System.Windows.Forms.Application.StartupPath;
-
//获取启动了应用程序的可执行文件的路径及文件名
-
string path7 = System.Windows.Forms.Application.ExecutablePath;
-
StringBuilder str=new StringBuilder();
-
str.AppendLine("System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName:" + path1);
-
str.AppendLine("System.Environment.CurrentDirectory:" + path2);
-
str.AppendLine("System.IO.Directory.GetCurrentDirectory():" + path3);
-
str.AppendLine("System.AppDomain.CurrentDomain.BaseDirectory:" + path4);
-
str.AppendLine("System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase:" + path5);
-
str.AppendLine("System.Windows.Forms.Application.StartupPath:" + path6);
-
str.AppendLine("System.Windows.Forms.Application.ExecutablePath:" + path7);
-
string allPath = str.ToString();
-
/* 输出结果
-
* System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName:D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release\XmlAndXsd.vshost.exe
-
System.Environment.CurrentDirectory:D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release
-
System.IO.Directory.GetCurrentDirectory():D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release
-
System.AppDomain.CurrentDomain.BaseDirectory:D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release\
-
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase:D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release\
-
System.Windows.Forms.Application.StartupPath:D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release
-
System.Windows.Forms.Application.ExecutablePath:D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release\XmlAndXsd.EXE
-
*/
相关文章
- C#操作符??和?:
- 如何使用T-SQL备份还原数据库及c#如何调用执行? C#中索引器的作用和实现。 jquery控制元素的隐藏和显示的几种方法。 localStorage、sessionStorage用法总结 在AspNetCore中扩展Log系列 - 介绍开源类库的使用(一) span<T>之高性能字符串操作实测
- Jquery如何序列化form表单数据为JSON对象 C# ADO.NET中设置Like模糊查询的参数 从客户端出现小于等于公式符号引发检测到有潜在危险的Request.Form 值 jquery调用iframe里面的方法 Js根据Ip地址自动判断是哪个城市 【我们一起写框架】MVVM的WPF框架(三)—数据控件 设计模式之简单工厂模式(C#语言描述)
- C#中泛型方法与泛型接口 C#泛型接口 List<IAll> arssr = new List<IAll>(); interface IPerson<T> c# List<接口>小技巧 泛型接口协变逆变的几个问题
- C#字符串数组排序 C#排序算法大全 C#字符串比较方法 一个.NET通用JSON解析/构建类的实现(c#) C#处理Json文件 asp.net使用Jquery+iframe传值问题
- C#获取当前路径的七种方法
- [C#基础]c#中的BeginInvoke和EndEndInvoke
- C#学习记录——密封类与密封方法
- C# DataTable类型 转换成 List集合类型的方法
- C#【通用方法】字节数组添加、移除、获取的方法类(妙用List<byte>,开发中常用)
- C#,深度好文,精致好码,文本对比(Text Compare)算法与源代码
- c#和c++的opencv位图数据参数互换问题解决方法
- C#获取当前程序运行路径的方法集合
- c# String常用方法
- .NET/C# 反射的的性能数据,以及高性能开发建议(反射获取 Attribute 和反射调用方法)——转载
- C#获取时间戳的封装方法函数+使用获取当前时间时间戳
- C#命名空间
- C#获取汉字字符串拼音首字母的方法(转载)
- 这才是正确解决方法:VS写C#项目时,导入MySQL数据源返回错误/报错 “You have a usable connection already“
- C# 基元线程同步构造
- C#Winform频繁刷新导致界面闪烁解决方法
- C# 高效过滤DataTable 中重复数据方法
- C#获取当前程序运行路径的方法集合