嗨,我有一个Path.Combine的问题,它没有返回corect结果.这就是我的意思.我将4个字符串组合成浴缸:
string basePath = "D:\\Programare\\Visual Studio\\TFS Workspace\\CodeArt\\Development\\CodeArt\\Backend\\WebApi\\CodeArt.WebApi\\bin\\..\\Content\\"
string userId = "4d52ec77-966a-480a-a4c3-c1ff67438fe9";
string filePath = "\\Avatar";
string storageFileName = "ffdc24a9-f553-41ce-aa33-042b07fcfdab.png";
var result = Path.Combine(basePath , userId , filePath , storageFileName);
Run Code Online (Sandbox Code Playgroud)
现在由于某种原因,我的这段代码只返回"\ Avatar\ffdc24a9-f553-41ce-aa33-042b07fcfdab.png".
我做错了什么为什么不是Path.Combine concatantes所有的字符串.
来自MSDN: Path.Combine(String, String, String, String)
path1应该是绝对路径(例如,"d:\ archives"或"\ archives\public").如果其中一个后续路径也是绝对路径,则组合操作会丢弃所有先前组合的路径并重置为该绝对路径路径.
Asper MSDN文档Path1应该是一个Absolute Path,你不应该Absolute Path在任何后续路径中
替换这个:
string filePath = "\\Avatar";
Run Code Online (Sandbox Code Playgroud)
有了这个:
string filePath = "Avatar";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
266 次 |
| 最近记录: |