Get final part of current URL (1 Viewer)

KevinM

Registered User.
Local time
Today, 20:23
Joined
Jun 15, 2000
Messages
719
On an index.asp or aspx page I need to capture the last part of the current url path (after the final slash)

e.g.

Http://www.myweb/myfolder/mysub

In this case it's 'mysub' I need to get, bearing in mind the number of slashes before it may no be known.

I'm sure there's an easy way using instr or instrRev which I could never get my head round in vb

Many Thanks
 

Sergeant

Someone's gotta do it
Local time
Today, 15:23
Joined
Jan 4, 2003
Messages
638
=Mid(MyURL, InStrRev(MyURL, "/") + 1)
 
Last edited:

KevinM

Registered User.
Local time
Today, 20:23
Joined
Jun 15, 2000
Messages
719
EDIT

Thanks, but i'm getting the current 'index.asp' rather than the folder name from my code...

I guess it should re-phrase it to 'second to last' '/'

So...

From

Http://www.myweb/myfolder/mysub/index.asp

I need just 'mysub'

Dim strCurrentURL
Dim strAlias

strCurrentURL = Request.ServerVariables("SERVER_NAME") _
& Request.ServerVariables("URL")

strAlias=Mid(strCurrentURL , InStrRev(strCurrentURL, "/") + 1)

Response.Write(strCurrentURL) & "<br>"
Response.Write(strAlias) & "<br>"


Cheers
 
Last edited:

KevinM

Registered User.
Local time
Today, 20:23
Joined
Jun 15, 2000
Messages
719
OK SORTED.

Just found this Function...

Function GetThisPath()
aPath = Request.ServerVariables("Path_Info")
pathArr = Split(aPath, "/")

For i = 1 to uBound(pathArr) - 1 'Offset page Name
'Loop thru path and return current directory only
GetThisPath = pathArr(i)
Next

IF GetThisPath = "" Then
GetThisPath = "/" 'We are at the Root level
End IF
End Function

This is from a 'breadcrumbs' routine which extracts the 'final folder' only
 

Kodo

"The Shoe"
Local time
Today, 15:23
Joined
Jan 20, 2004
Messages
707
split on the /

strCurrentURL=split(request.servervariables("URL"),"/")
ThisFolder=strCurrentURL(ubound(strCurrentURL)-1)
 

Users who are viewing this thread

Top Bottom