我正在使用以下方法检索当前路径:
Dim paths As String = HttpContext.Current.Request.FilePath
返回/VHP/hmo.aspx
我需要缩小范围的是文件夹(VHP)。如何删除之前的/
和之后的/filename
?
答案 0 :(得分:2)
这对你有用吗?
Dim paths As String = HttpContext.Current.Request.FilePath
Dim dir as String= Path.GetDirectoryName(Server.MapPath(path))
<强>更新强> 根据你的代码,你应该这样做:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strFileNamePath As String = System.IO.Path.GetDirectoryName(Server.MapPath(HttpContext.Current.Request.FilePath))
''some how grab the working folder name here
If strFileNamePath = "xyz" Then
'do this
Else If strFileNamePath = "abc" then
'do this'
End If
End Sub
请注意我为HttpContext.Current.Request.Url.AbsolutePath
HttpContext.Current.Request.FilePath
的方式