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
-
*/
相关文章
- .NET压缩图片保存 .NET CORE WebApi Post跨域提交 C# Debug和release判断用法 tofixed方法 四舍五入 (function($){})(jQuery); 使用VUE+iView+.Net Core上传图片
- 采用异步来实现重新连接服务器或者重新启动服务 C#中类的属性的获取 SignalR2简易数据看板演示 C#动态调用泛型类、泛型方法 asp .net core Get raw request. 从壹开始前后端分离[.NetCore 不定期更新] 38 ║自动初始化数据库
- 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#使用oledb连接excel运行Insert Into语句出现“操作必须使用一个可更新的查询”的解决的方法
- Word控件Spire.Doc 【文本】教程(12) ;新方法在 C# 中获取 Word 文档中内容控件的别名、标签和 ID
- C# .NET 从dapper调用存储过程,该存储过程接受用户定义表类型的列表【实战】
- C# 格式化XML方法
- 浅谈C# .Net技术面试 , 正在找工作的人一定要看看
- C# 获取可执行文件路径的上上级目录的方法
- C#中获取当前程序所在路径的各种方法示例
- C#获取当前程序运行路径的方法集合
- C# MVC站点 (安装SSL证书后) 实现 HTTP自动跳转到 HTTPS的Web.config设置方法
- C#有小数位数直接进位为整数;JavaScript Math有小数位数取整方法
- C# list 筛选FindAll
- C#中遍历各类数据集合的方法总结
- 对特殊字符编码js与c#中的处理方法
- 《C#零基础入门之百识百例》(三十二)方法参数 -- 引用&输出参数 -- 两数交换
- 《C#零基础入门之百识百例》(六十四)结构体在方法中的使用 -- 学生成绩排序 -- 排序拓展
- C# CheckedListBox控件的使用方法
- 关于C#中遍历字符串中的每个字符的方法
- C# 重写ComboBox实现下拉任意组件的方法