众所周知,某些程序需要我们获取其运行路径,并且在程序中使用该路径。在win32系统下,C#语言获取程序运行路径有很多种方法,比如:Application、AppDomain等等,相对来讲非常简单。而在windows mobile系统下,换言之,在.net cf下microsoft并未提供如此方便的方法,所以,在使用C#获取windows mobile系统下程序的运行路径就一波三折了。
方法如下:
//获取程序运行路径,最后不包含"/"
public static String GetAppRunPath()
{
return System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
}
其中:System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase获取了程序的运行路径及文件名
System.IO.Path.GetDirectoryName将文件名称剥离,只留下运行路径。
以上心得来自optidiy的开发过程!Good Luck!