Link to home
Start Free TrialLog in
Avatar of Martin Cotterill
Martin CotterillFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Get the current page's filename

Hi Experts

Is there an easy way to get the filename of the current page. The reason I ask this is that I use the same piece of code on many different pages and this would make life a little easier and be a lot more forgiving of my increasing 'senior moments'.

It has to fit in with the existing code, which is:

<%
' Automatically populate link with filename by B_Dorsey at Experts Exchange
' https://www.experts-exchange.com/questions/22148871/Automatically-populate-link-with-filename.html?cid=239#18465161
' incorperating a script to find and replace cr/lf with HTML line breaks by b0lsc0tt also at EE
' https://www.experts-exchange.com/questions/22127810/Replace-cr-lf-in-ASP.html#18343873
' Using Multiple RegExp statements by B_Dorsey at Experts Exchange
' https://www.experts-exchange.com/questions/22396646/Multiple-RegExp-statements.html
' If you use this code (or any part of it) please keep this header intact.
' These guys did the work, they deserve the credit. Many thanks.
      
      Dim objRegExp
      Set objRegExp = New RegExp
      objRegExp.IgnoreCase = True
      objRegExp.Global = True
      objRegExp.Pattern = "<id=([^>]+)+>" ' Populate Link
      
      sContent = Replace(rsContent.Fields.Item("Content").Value, vbcrlf, "<br />") ' Find & replace
      sContent = objRegExp.Replace(sContent, "<div id=more><a href=DonationsAndFundraising.asp?id=$1 class=more>[ Find out more ]</a></div>")

      ' Multiple RegExp
      sContent = Replace(sContent,"'","&#39;")
      sContent = Replace(sContent,"<charityName>",(rsCharityDetails.Fields.Item("CharityName").Value))
      sContent = Replace(sContent,"<b>","<b class='contentHead'>")
      ' End of Multiple RegExp
      
      response.write sContent
      Set objRegExp = Nothing
%>

The filename code will replace the filename in the line:

      sContent = objRegExp.Replace(sContent, "<div id=more><a href=DonationsAndFundraising.asp?id=$1 class=more>[ Find out more ]</a></div>")

which, in this case, is:

           'DonationsAndFundraising'

All the filenames that will be used have the '.asp' extension.

Warm regards

Martin
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

>>Is there an easy way to get the filename of the current page.
try:

response.write request.ServerVariables("SCRIPT_NAME")

?
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Martin Cotterill

ASKER

Hi ryancys

That get the directory and filename.

How would I cut it down to get just the filename?

Regards

Martin
Hello again ryancys

Our posts crossed but your second post did the trick.

Absolutely brilliant!

Many thanks. That's helped me no end.

Warm regards

Martin
Glad could make some help here, cheers :^)