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

  • Thread starter Thread starter Darrel
  • Start date Start date
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
 
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.




Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
 

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

Back
Top