Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.net获取路径_C#_Asp.net - Fatal编程技术网

C# ASP.net获取路径

C# ASP.net获取路径,c#,asp.net,C#,Asp.net,我有 如何将其转换为 C:\Softwares\Test\ASPnetTest\Project11\Shared\Public\Images\ 谢谢。如果您想要URL中使用的路径: 您可以使用类似的方法(类在C中也是有效的): …为了使它更容易: Public Function MapURL(ByVal Path As String) As String Dim AppPath As String = _ HttpContext.Current.Server.MapPath

我有

如何将其转换为

C:\Softwares\Test\ASPnetTest\Project11\Shared\Public\Images\

谢谢。

如果您想要URL中使用的路径:

您可以使用类似的方法(类在C中也是有效的):

…为了使它更容易:

Public Function MapURL(ByVal Path As String) As String
     Dim AppPath As String = _
     HttpContext.Current.Server.MapPath("~")
     Dim url As String = String.Format("~{0}" _
     , Path.Replace(AppPath, "").Replace("\", "/"))
     Return url
End Function
如果需要文件夹,请相对于应用程序的基本路径:

请求。PhysicalApplicationPath
将为您提供
c:\softwares\test\aspnettest\project11
部分。然后你可以得到相关的部分,请看下面的答案:


我正在检索目录列表(物理路径)并将其显示为逻辑路径。是的,已解决,但请将第二行更改为:返回字符串.Format(“~/{0}”,path.Replace(appPath,”)。Replace(“\\”,“/”);可能是打字错误。:)我看不出有什么不同,您更改/修复了什么?:)我将“{0}”更改为“~/{0}”。我确认。
Public Function MapURL(ByVal Path As String) As String
     Dim AppPath As String = _
     HttpContext.Current.Server.MapPath("~")
     Dim url As String = String.Format("~{0}" _
     , Path.Replace(AppPath, "").Replace("\", "/"))
     Return url
End Function
private static string MapUrl(string path)
{
    var appPath = HttpContext.Current.Server.MapPath("~");
    return string.Format("~{0}", path.Replace(appPath, "").Replace("\\", "/"));
}