By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,269 Members | 1,332 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,269 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
May 16 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Use this function to strip out the filename:

System.IO.Path.GetFileName(sPath)

Here's more info:
http://windowssdk.msdn.microsoft.com...1_16219e3a.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Darrel" <no*****@nospam.com> wrote in message
news:Ol**************@TK2MSFTNGP03.phx.gbl...
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

May 16 '06 #2

P: n/a
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/
===================================
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:uW**************@TK2MSFTNGP04.phx.gbl...
Use this function to strip out the filename:

System.IO.Path.GetFileName(sPath)

Here's more info:
http://windowssdk.msdn.microsoft.com...1_16219e3a.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Darrel" <no*****@nospam.com> wrote in message news:Ol**************@TK2MSFTNGP03.phx.gbl...
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


May 16 '06 #3

P: n/a
> Use this function to strip out the filename:

System.IO.Path.GetFileName(sPath)
I hope this helps


It does. Thanks!

-Darrel
May 17 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.