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

Asp.net 如何在vb.net中识别工作文件夹,asp.net,vb.net,Asp.net,Vb.net,我正在使用以下命令检索当前路径: Dim paths As String = HttpContext.Current.Request.FilePath 返回类似于/VHP/hmo.aspx的内容 我需要缩小的是文件夹(VHP)。如何删除前面的/和后面的/filename?这对您有用吗 Dim paths As String = HttpContext.Current.Request.FilePath Dim dir as String= Path.GetDirectoryName(Server

我正在使用以下命令检索当前路径:

Dim paths As String = HttpContext.Current.Request.FilePath
返回类似于
/VHP/hmo.aspx的内容


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

这对您有用吗

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

的,我意识到我已经用C#:d写了我的初始答案,当我使用你的建议时,我在“Path.GetDirectoryName”下面有“swigly”行,比如,“'GetDirectoryName'不是'System.Web.UI.WebControl.Label'的成员。”。我的codebehind上缺少“Imports…”吗?@BeckaBear是的,你缺少使用System.IO的
--即使添加了Imports System.IO(相同的错误),仍然没有运气。如果有区别的话,我使用的是.NET Framerwork 3.5。“应该起作用”的东西就是不。。。sigh@BeckaBear因为根据错误,您正试图在标签上调用GetDirectoryName。发布你的全部代码,我会准确指出你需要做什么。