how to get the name of the current aspx file?

D

Dave

Hi,

i need to get the name of the current aspx file in code-behind.
Assume the current aspx file is "myfile.aspx", i want to put value "myfile"
into a variable in code-behind.
Is that possible?

Thanks
Dave
 
J

John Saunders [MVP]

Dave said:
Hi,

i need to get the name of the current aspx file in code-behind.
Assume the current aspx file is "myfile.aspx", i want to put value
"myfile" into a variable in code-behind.
Is that possible?


You can get the name of the current _class_ via GetType().Name. This may or
not be the name of the file, but then I can't tell if you mean file or
class.
 
B

bruce barker

you can get from Request.FilePath, by removing the leading dir string.

-- bruce (sqlwork.com)
 
M

Mark Rae

i need to get the name of the current aspx file in code-behind.
Assume the current aspx file is "myfile.aspx", i want to put value
"myfile" into a variable in code-behind.
Is that possible?

using System.IO;
string strFile = Path.GetFileNameWithoutExtension(Request.FilePath);
 
J

Juan T. Llibre

System.IO.Path.GetFileName(Request.ServerVariables("SCRIPT_NAME"))

....works, too.
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top