用C#在WinXP和WinCE里获取应用程序当前路径
下面的“CurrentPath”属性可以获取应用程序的当前路径,经测试,在WinXP与WinCE下均正常运行。
PS:可以写成静态方法,编译到动态库里,到处都可以用了。
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()
{
}