Request.FilePath gets full path...built in way to grab just the filename?

D

Darrel

using Request.FilePath will return the entire file path:

directory/directory/myfile.aspx

Is there a built function in ASP.net to grab just the filename (myfile.aspx)
or do I need to write some string manipulation functions to grab it out of
the filepath?

-Darrel
 
J

Juan T. Llibre

Here's a complete example using the script_name server variable for the path:

string pagename = System.IO.Path.GetFileName(Request.ServerVariables["SCRIPT_NAME"]);

The pagename string variable will contain "myfile.aspx",
if that code is included in myfile.aspx's Page_Load event or any suitable page event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top