winform中相对路径和绝对路径的获取
例如:
Path.GetFullPath(Path.Combin(@"C:\a\b\c","..\b.text"));
..代表上级目录
.代表当前目录
结果:
c:\a\b\b.text
在winform中项目所在目录:D:\MyWork\MyProject
string strpath=System.Windows.Forms.Application.StartupPath;
结果:
strpath: D:\MyWork\MyProject\bin\Debug
string _path=Path.GetFullPath(Path.Combin(strpath,"..\b.text"));
结果:
_path: D:\MyWork\MyProject\bin\b.text
string _path2=Path.GetFullPath(Path.Combin(strpath,"..\..\b.text"));
结果:
_path2: D:\MyWork\MyProject\b.text