如何在智能设备应用程序中获取应用程序的路径?

时间:2010-03-04 07:38:39

标签: c# smartphone

我正在开发C#中的智能设备应用程序。我想要我的应用程序的确切路径。我的应用程序驻留在我的机器上的F:/ MobileAppl / ManagedAppl。

所以我想在智能设备应用程序中使用此路径。

请确保.net框架的所有功能在.net compact框架中不起作用。

您能否提供我可以解决上述问题的代码或链接?

3 个答案:

答案 0 :(得分:1)

public static string getPath() 
{
    string fullname;
    string myAppPath;
    fullname = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
    myAppPath = System.IO.Path.GetDirectoryName(fullname);
    myAppPath = myAppPath.Replace("file:\\", "");
    return myAppPath;
}

答案 1 :(得分:1)

这应该适用于Windows应用程序和移动应用程序

 string path;
 path = System.IO.Path.GetDirectoryName( 
 System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase );

link text

答案 2 :(得分:0)

 string path = System.IO.Path.GetDirectoryName( 
 System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase );

此代码不会返回正确的路径。

我的应用程序路径是D:/ Test / MobilApplication。

执行上面的代码时,它只显示“//程序文件// MobilApplication”。