Chi*_*ong 8 c# compact-framework windows-mobile filepath
我想获得我的应用程序的路径,如:"\\ ProgramFiles \\ myApp",我尝试使用以下代码:
string path = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
Run Code Online (Sandbox Code Playgroud)
但它返回一个末尾有"\\ myapp.exe"的路径.
我也尝试过:
string path = System.IO.Directory.GetCurrentDirectory();
Run Code Online (Sandbox Code Playgroud)
但它会抛出"NotSupportedException".
有没有办法在没有.exe的情况下获得一条路径?
Fre*_*örk 18
Application.StartupPath 应该为你做到这一点.
更新:从您编辑我看到您在Compact Framework上运行.然后Application.StartupPath将无法正常工作.这是我通常使用的构造:
private static string GetApplicationPath()
{
return System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
}
Run Code Online (Sandbox Code Playgroud)
Dan*_*röm 10
path = System.IO.Path.GetDirectoryName( path );
Run Code Online (Sandbox Code Playgroud)