我正在用 C# 开发智能设备应用程序。我想要我的应用程序的确切路径。我的应用程序驻留在我的机器上 F:/MobileAppl/ManagedAppl。
所以我想在智能设备应用程序中使用这条路径。
请确保 .net 框架的所有功能在 .net 紧凑框架中不起作用。
您能否提供我可以解决上述问题的代码或链接?
我正在用 C# 开发智能设备应用程序。我想要我的应用程序的确切路径。我的应用程序驻留在我的机器上 F:/MobileAppl/ManagedAppl。
所以我想在智能设备应用程序中使用这条路径。
请确保 .net 框架的所有功能在 .net 紧凑框架中不起作用。
您能否提供我可以解决上述问题的代码或链接?
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;
}
这应该适用于 Windows 应用程序和移动应用程序
string path;
path = System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase );
string path = System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase );
此代码不会返回正确的路径。
我的应用程序路径是 D:/Test/MobilApplication。
在执行上面的代码时,它会像这样简单地显示“//程序文件//MobilApplication”。