我正在创build一个应用程序,可以在任何Windows版本中执行,即使在移动设备上,我正在尝试获取可执行文件的当前目录。 问题是,如果我使用下面的代码,它不会在Windows Mobile中编译:
string currentDirectory = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
如果我使用这个代码,我会收到类似于: file:\ C:\ xxx
string currentDirectory = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
虽然,我需要获取根驱动器,并且此代码不能在Windows Mobile中编译:
String rootPath = Path.GetPathRoot(Environment.SystemDirectory);
有谁知道如何获取应用程序的当前目录和任何Windows版本的根path,甚至移动的?
东西沿着这些线?
var folder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)