C#在WinXP和WinCE里获取应用程序当前路径的通用函数

来源:互联网 发布:csdn设备运维算法 编辑:程序博客网 时间:2024/05/16 18:29

PS:可以写成静态方法,编译到动态库里,到处都可以用了。
using System.IO;
using System.Reflection;
public class Configs
 {
  private string m_CurrentPath;
 
  private string Platform
  {
   get
   {
    return Environment.OSVersion.Platform.ToString();
   }
  }
 
  public string CurrentPath
  {
   get
   {
   
    if(Platform.Equals("WinCE"))
    {
     m_CurrentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
    }
    else if(Platform.Equals("Win32NT"))
    {
     m_CurrentPath = Directory.GetCurrentDirectory();
    }

    return m_CurrentPath;
   }
  }
 
  public Configs()
  {
  
  }
 }