C# 如何将URL与根目录合并

C# 如何将URL与根目录合并,c#,asp.net,string,C#,Asp.net,String,这是一个愚蠢的问题。我希望能得到一些快速的答案 我正在尝试通过FTP访问文件,其路径如下: /contents/member/PetePentreath/photos/thumbs/0d136985-1.png" "E:\\Downloads\\YourTimeSite\\YourTimeSite\\/contents/member/PetePentreath/photos/thumbs/0d136985-1.png" 我正在尝试编写一个包含文件目录根的路径。我正在使用HttpContext

这是一个愚蠢的问题。我希望能得到一些快速的答案

我正在尝试通过FTP访问文件,其路径如下:

/contents/member/PetePentreath/photos/thumbs/0d136985-1.png"
"E:\\Downloads\\YourTimeSite\\YourTimeSite\\/contents/member/PetePentreath/photos/thumbs/0d136985-1.png"
我正在尝试编写一个包含文件目录根的路径。我正在使用
HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath)
并将其与文件的路径连接起来,该路径为我提供如下输出:

/contents/member/PetePentreath/photos/thumbs/0d136985-1.png"
"E:\\Downloads\\YourTimeSite\\YourTimeSite\\/contents/member/PetePentreath/photos/thumbs/0d136985-1.png"

这不是url的正确格式。正确的方法是什么?

是否尝试将“/contents/member/PetePentreath/photos/thumbs/0d136985-1.png”字符串中的“/”更改为“\”?您可以在C#中使用String.Replace执行此操作

然后,将其与对HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath)的调用连接起来,这将返回正确的路径