获取当前进程的绝对路径:
Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
获取指定相对路径的绝对路径:
Path.Combine(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName), ConfigurationManager.AppSettings[
"
FileRoot
"
]);
其中"FileRoot"定义在配置文件内:
<
add key
=
"
FileRoot
"
value
=
"
./
"
/>
对相对路径的绝对化使用这种组合方法的原因在于,在某些情况下(例如运行在XP下的C-S程序中),如果直接使用相对路径会出现不可预知的路径指向错误。