C# 获取当前路径7种方法
//获取模块的完整路径。
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# 获取当前路径7种方法的更多相关文章
- 【转】C#获取当前路径7种方法
webformvar s = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; //C盘 IIS路径 var s1 ...
- [No00006F]总结C#获取当前路径的各种方法
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- Spring3 MVC请求参数获取的几种方法
Spring3 MVC请求参数获取的几种方法 一. 通过@PathVariabl获取路径中的参数 @RequestMapping(value="user/{id}/{name}&q ...
- Struts2获取request三种方法
Struts2获取request三种方法 struts2里面有三种方法可以获取request,最好使用ServletRequestAware接口通过IOC机制注入Request对象. 在Actio ...
- Spring3 MVC请求参数获取的几种方法[转]
Spring3 MVC请求参数获取的几种方法 Spring3 MVC请求参数获取的几种方法 一. 通过@PathVariabl获取路径中的参数 @RequestMapping(value=& ...
- Java反射定义、获取Class三种方法
反射机制的定义: 在运行状态时(动态的),对于任意一个类,都能够得到这个类的所有属性和方法. 对于任意一个对象,都能够调用它的任意属性和方法. Class类是反射机制的起源,我们得到Class类对象 ...
- 转载-centos网络配置(手动设置,自动获取)的2种方法
转载地址:http://blog.51yip.com/linux/1120.html 重新启动网络配置 # service network restart 或 # /etc/init.d/networ ...
- centos网络配置(手动设置,自动获取)的2种方法3
不知道为什么最近一段时间网络特别的慢,还老是断,断的时候,局域网都连不上,当我手动设置一下ip后就可以了,搞得我很无语.下面是2种设置网络连接的方法,在说怎么设置前,一定要做好备份工作,特别是对于新手 ...
- springmvc请求参数获取的几种方法
1.直接把表单的参数写在Controller相应的方法的形参中,适用于get方式提交,不适用于post方式提交. /** * 1.直接把表单的参数写在Controller相应的方法的形参中 * @pa ...
随机推荐
- AutoIt操作Windows GUI实现文件上传
AutoIt 一个使用类似BASIC脚本语言的免费软件,用于Windows GUI(图形用户界面)中进行自动化操作.它利用模拟键盘按键,鼠标移动和窗口/控件的组合来实现自动化任务. 官方网站: htt ...
- MVC代码中如何调用api接口
关于代码解释,为了方便读者浏览时更好理解代码的含义,我把注释都写在代码里面了.因为一开始我只考虑到功能上的实现并没有考虑代码的优化所以代码我就全写在一个页面了.至于那些生成扑克牌类.计算类等代码优化方 ...
- nginx开启日志,指定格式,查看执行时间
nginx配置: access_log on; log_format access '$remote_addr – $remote_user [$time_local] "$request& ...
- 【转】如何把Json格式字符写进text文件中
http://www.cnblogs.com/insus/p/4306640.html http://json2csharp.chahuo.com/ 本篇一步一步学习怎样把显示于网页的json格式的字 ...
- MXNET安装过程中遇到libinfo导入不了的问题解决
今天尝试安装windows版本的MXNET,在按照官网的运行了python的setup之后,import mxnet时出现如下错误:cannot import name libinfo,在网上查找发现 ...
- Linux从零单排(二):setuptools、pip、anaconda2的环境配置
为了更方便的使用Python的类库,需要进行相应的配置 (一)setuptools的配置 1.setuptools的下载 命令行输入wget https://pypi.python.org/packa ...
- ACM集训的第。。。诶~不知道第几题=.=
题目: 郭铮鹏认为排序是一种很频繁的计算任务,所以他考虑了一个简单的问题:现在最多只有三值的排序问题.一个实际的例子是,当我们给某项竞赛的优胜者按金银铜牌排序的时候.在这个任务中可能的值只有三种1,2 ...
- Echarts学习笔记之饼图
注:ECHarts的相关文件请到ECharts官网下载,下载地址:http://echarts.baidu.com/download.html 1.前台 <div style="ali ...
- WP8.1 和UWP 如何使用下载网页的上的音频 并保存
WP8.1: private async Task<StorageFile> GetVoiceData() { HttpClient httpclient = new HttpClient ...
- LeetCode Power of Four
原题链接在这里:https://leetcode.com/problems/power-of-four/ 题目: Given an integer (signed 32 bits), write a ...