如何识别vb.net中的工作文件夹

时间:2011-09-20 18:45:31

标签: asp.net vb.net

我正在使用以下方法检索当前路径:

Dim paths As String = HttpContext.Current.Request.FilePath

返回/VHP/hmo.aspx

之类的内容

我需要缩小范围的是文件夹(VHP)。如何删除之前的/和之后的/filename

1 个答案:

答案 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的方式