zoukankan      html  css  js  c++  java
  • c#获取相对路径的八种方法

    c#获取相对路径的八种方法

       C#获取相对路径1.
      
      获取和设置当前目录的完全限定路径。
      
      
      string str = System.Environment.CurrentDirectory; Result: C:\xxx\xxx
      C#获取相对路径2.
      
      获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。
      
      
      string str = System. Windows .Forms.Application.StartupPath; Result: C:\xxx\xxx
      C#获取相对路径3.
      
      获取新的 Process 组件并将其与当前活动的进程关联的主模块的完整路径,包含文件名。
      
      
      string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; Result: C:\xxx\xxx\xxx.exe
      C#获取相对路径4.
      
      获取当前 Thread 的当前应用程序域的基目录,它由程序集冲突解决程序用来探测程序集。
      
      
      string str = System.AppDomain.CurrentDomain.BaseDirectory; Result: C:\xxx\xxx\
      C#获取相对路径5.
      
      获取应用程序的当前工作目录。
      
      
      string str = System.IO.Directory.GetCurrentDirectory(); Result: C:\xxx\xxx
      C#获取相对路径6.
      
      获取和设置包含该应用程序的目录的名称。
      
      
      string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase; Result: C:\xxx\xxx\
      C#获取相对路径7.
      
      获取当前进程的完整路径,包含文件名。
      
      
      string str = this.GetType().Assembly.Location; Result: C:\xxx\xxx\xxx.exe
      C#获取相对路径8.
      
      获取启动了应用程序的可执行文件的路径,包括可执行文件的名称。
      
      
      string str = System. Windows .Forms.Application.ExecutablePath; Result: C:\xxx\xxx\xxx.exe
      此外,更多见的通过XML文件配置具体的路径来达到合理的规划配置文件的具体存放位置,如WEB中的配置文件中的路径

          应用示例

                string path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"module\M3Example\MuColor.txt";
                StreamReader smRead = new StreamReader(path, System.Text.Encoding.Default); //设置路径

  • 相关阅读:
    墨西哥选美皇后涉毒被捕 丢失桂冠
    html中的超连接和鼠标事件
    用SSL安全协议实现WEB服务器的安全性
    PHP中的一些经验积累 一些小巧实用的函数
    博客特效之背景动画雨滴(转帖)
    smarty中section的使用
    程序员语录
    css常用属性
    10年软件开发教会我最重要的10件事[转]
    WP7中对ListBox的ItemTemplate中子元素的后台操作
  • 原文地址:https://www.cnblogs.com/shuzhengyi/p/1946266.html
Copyright © 2011-2022 走看看