WelcomeServicesPortfolioKnowledge BaseContact Us
27 Seconds, Inc.


Knowledge base View Article

need hosting?

Need hosting? We use and love our host - CrystalTech.com!
Need hosting? We use and love our host - CrystalTech.com!

Text Disguise - CAPTCHA-image/Human Interactive Proof web services

National Holiday Dates and Bank Holiday Dates - web site that provides the dates of national and bank holidays for the United States, United Kingdom, Ireland and Scotland

Holiday Web Service - web services for programmers to provide the dates of national and bank holidays in their applications for the United States, United Kingdom, Ireland and Scotland

Our Family Heart - web site to help families communicate no matter where they are

What?! You haven't heard about the greatest remote controlled flyer to come out in years?! Checkout the FlyTech DragonFly now!

Get just the filename of the current page.

Summary: Returns just the filename portion the current page you are on.
 
Keywords: FILENAME
NAME
SCRIPT
SCRIPT_NAME
SERVERVARIABLES
Applicable Software: Active Server Pages (ASP)
 
Body:

I recently needed to make log files which were based on the name of the ASP page that I was writing. I decided to use a shared function for the log writing and didn't want to hard-code the call to the function on every page. So, I came up with this routine to get the filename of the current page:

Function getBaseFilename()
Dim sScript: sScript = Request.ServerVariables("script_name")
Dim sOut

Dim iLocStart, iLocEnd
	iLocStart = InStrRev(sScript, "/")
	If iLocStart > 0 Then
		iLocEnd = InStr(iLocStart, sScript, ".")
		If iLocEnd > 0 Then
			sOut = Mid(sScript, iLocStart + 1, iLocEnd - iLocStart - 1)
		Else
			sOut = Right(sScript, iLocStart)
		End If
	Else
		sOut = sScript
	End if
	
	getBaseFileName = sOut
	
End Function

To use it, I did:

Dim sFileName
    sFileName = getBaseFileName()

    Response.Write sFileName

 
Author: Douglas L. Setzer, II, http://www.27seconds.com
Posted On: 3/5/2002 11:26:15 AM

Rate this article: Average: n/a
n/a12345678910
Comments?

Article Search   |   All Articles

 

 
©2002 27 Seconds, Inc. All Rights Reserved.