• 【转】C#(ASP.Net)获取当前路径的方法集合


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

    [c-sharp] view plaincopy
     
    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中三种获取当前路径的代码

    [c-sharp] view plaincopy
     
    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);  
  • 相关阅读:
    get请求中文乱码及get,post编码探究
    spring使用redis做缓存
    tomcat中session在两个webapp中实现共享
    JDK8 HashMap 源码解析
    Windows Apache服务器配置
    怎么使用IDEA
    面试中的Java链表
    设计模式解密(12)- 桥接模式
    Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    设计模式解密(11)- 命令模式
  • 原文地址:https://www.cnblogs.com/mo-wang/p/4389594.html
Copyright © 2020-2023  润新知