转自:http://www.gaobo.info/read.php/660.htm

  1. //获取当前进程的完整路径,包含文件名(进程名)。
  2. string str = this.GetType().Assembly.Location;
  3. result: X:/xxx/xxx/xxx.exe (.exe文件所在的目录+.exe文件名)
  4. //获取新的 Process 组件并将其与当前活动的进程关联的主模块的完整路径,包含文件名(进程名)。
  5. string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
  6. result: X:/xxx/xxx/xxx.exe (.exe文件所在的目录+.exe文件名)
  7. //获取和设置当前目录(即该进程从中启动的目录)的完全限定路径。
  8. string str = System.Environment.CurrentDirectory;
  9. result: X:/xxx/xxx (.exe文件所在的目录)
  10. //获取当前 Thread 的当前应用程序域的基目录,它由程序集冲突解决程序用来探测程序集。
  11. string str = System.AppDomain.CurrentDomain.BaseDirectory;
  12. result: X:/xxx/xxx/ (.exe文件所在的目录+"/")
  13. //获取和设置包含该应用程序的目录的名称。
  14. string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
  15. result: X:/xxx/xxx/ (.exe文件所在的目录+"/")
  16. //获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。
  17. string str = System.Windows.Forms.Application.StartupPath;
  18. result: X:/xxx/xxx (.exe文件所在的目录)
  19. //获取启动了应用程序的可执行文件的路径,包括可执行文件的名称。
  20. string str = System.Windows.Forms.Application.ExecutablePath;
  21. result: X:/xxx/xxx/xxx.exe (.exe文件所在的目录+.exe文件名)
  22. //获取应用程序的当前工作目录(不可靠)。
  23. string str = System.IO.Directory.GetCurrentDirectory();
  24. result: X:/xxx/xxx (.exe文件所在的目录)

.NET中三种获取当前路径的代码

  1. //Web编程
  2. HttpContext.Current.Server.MapPath("FileName")
  3. System.Web.HttpContext.Current.Request.Path
  4. //Windows编程
  5. System.Environment.CurrentDirectory
  6. //Mobile编程
  7. Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

【转】C#(ASP.Net)获取当前路径的方法集合的更多相关文章

  1. ASP.NET获取根目录的方法集合

    编写程序的时候,经常需要用的项目根目录,自己总结如下: 1.取得控制台应用程序的根目录方法 方法1.Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径 方法 ...

  2. C#获取当前路径的方法

    C#获取当前路径的方法如下: 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName -获取模块的完整路径. 2. ...

  3. ASP.NET获取路径的方法

    原文:[转载]ASP.NET获取路径的方法 HttpContext.Current.Request.PhysicalPath;    // 获得当前页面的完整物理路径.比如 F:\XFU.NSQS\p ...

  4. Winform获取应用程序的当前路径的方法集合(转)

    Winform获取应用程序的当前路径的方法集合,具体如下,值得收藏 //获取当前进程的完整路径,包含文件名(进程名). string str = this.GetType().Assembly.Loc ...

  5. Java 获取当前路径的方法总结

    Java 获取当前路径的方法总结 1.利用System.getProperty()函数获取当前路径: System.out.println(System.getProperty("user. ...

  6. C#获取当前路径的方法如下

    1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName -获取模块的完整路径. 2. System.Environm ...

  7. java获取当前路径的方法

    1.System.getProperty("user.dir") 函数获取当前路径 // 获取当前路径方式1 System.out.println(System.getProper ...

  8. 【转载】ASP.NET获取路径的方法

    HttpContext.Current.Request.PhysicalPath;    // 获得当前页面的完整物理路径.比如 F:\XFU.NSQS\project\website\Default ...

  9. Python 获取当前路径的方法

    Python2.7 中获取路径的各种方法 sys.path 模块搜索路径的字符串列表.由环境变量PYTHONPATH初始化得到. sys.path[0]是调用Python解释器的当前脚本所在的目录. ...

随机推荐

  1. css写带边框的三角形

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. [转] FastMM使用详解

    FastMM使用详解 一.引言      FastMM 是适用于delphi的第三方内存管理器,在国外已经是大名鼎鼎,在国内也有许多人在使用或者希望使用,就连 Borland 也在delphi2007 ...

  3. 01背包 ZOJ 3931 Exact Compression

    题目连接 题意:n个数字构建哈夫曼树,问是否存在这样一棵树使得:(Fi数字大小,Ci哈夫曼表示下,'0'的数量) 分析:每次从优先队列取出两个数字可以互换位置,这样可以01互换.设a[i] <= ...

  4. web工程spring+ibatis单元测试

    web工程spring+ibatis在本地做单元测试,用例如下: package wanghongye; import org.junit.Before; import org.junit.Test; ...

  5. Shell 编程基础之 If 练习

    一.语法 if [ condition ]; then # 当 condition 成立时,执行内容: fi # 将 if 反过来写,fi 结束 if 之意 if [ condition ]; the ...

  6. sql over的作用及用法

    over不能单独使用,要和分析函数:rank(),dense_rank(),row_number()等一起使用.其参数:over(partition by columnname1 order by c ...

  7. Visual Studio: whether auto-building when press the debug button

    Tools -> Options -> Projects and Solutions->Build and Run -> choose an option for On Run ...

  8. 目前quanben评十大哲学家

    排名分先后,包含时间.地区和主要正面成就以及其他代表人物. 1. 伊曼努尔·康德:十八世纪:东普鲁士:理性的界限,现象和本体分立以及主体的地位2. 柏拉图:公元前三四百年:古希腊:理想(念)世界3. ...

  9. AVD模拟器运行异常

    The connection to adb is down, and a severe error has occured. (1)现将eclipse关闭 (2)打开命令行(cmd),输入:cd + ...

  10. highcharts 时间少8小时问题

    Highcharts 中默认开启了UTC(世界标准时间),由于中国所在时区为+8,所以经过 Highcharts 的处理后会减去8个小时. 如果不想使用 UTC,有2种方法可供使用: 1.在使用Hig ...