string basepath = @"C:\somefolder\subfolder\bin"; // is defined in runtime
string relative = @"..\..\templates";
string absolute = Magic(basepath, relative); // should be "C:\somefolder\templates"
Run Code Online (Sandbox Code Playgroud)
你能用Magic方法帮我吗?希望代码不会太复杂.
Magic.NET Framework中是否有" "方法?
Chr*_*isF 12
如果你看一下Path课程,有几种方法应该有所帮助:
Path.Combine
Run Code Online (Sandbox Code Playgroud)
和
Path.GetFullPath
Run Code Online (Sandbox Code Playgroud)
所以:
string newPath = Path.Combine(basepath, relative);
string absolute = Path.GetFullPath(newPath);
Run Code Online (Sandbox Code Playgroud)
虽然第二步并非严格要求 - 如果您打印出来,它会给您一条"更干净"的路径.
| 归档时间: |
|
| 查看次数: |
8408 次 |
| 最近记录: |