2/9/12

Get Physical Name of an ASP Page from a URL

Sometimes we need to get the physical name (from the bar adress of url) of an asp.net page to pass it by value or to loop throw project pages programmatically.


In that purpose we use a function to split the URL's string 

Public Function cutString(ByVal url As StringAs String
 
      Dim St1() As String
      St1 = Split(url, "/")
 
      For i = 0 To UBound(St1)
          cutString = St1(i)
      Next i
      cutString = St1(UBound(St1))
  End Function

and then get the whole Url and use our function that extract just the name of the page with its extension(.aspx)


Protected Sub Page_Load(ByVal sender As ObjectByVal As System.EventArgs) Handles Me.Load
  
Textbox1.Text=  cutString(Request.Url.ToString)
End Sub

No comments:

Post a Comment