Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET: Get Page's filename

I have an ASPX page named Default.aspx. From its codebehind on Page_Load(), I would like to get "Default.aspx", alone, into a string:

protected void Page_Load(object sender, EventArgs e)
{
    string aspxFileName = ?;
}

What should I replace ? with—what will get me the ASPX filename?

like image 602
JamesBrownIsDead Avatar asked Nov 28 '09 01:11

JamesBrownIsDead


People also ask

How to get Current page Name in c#?

string path = Server. MapPath(Page. AppRelativeVirtualPath);

How to get File Name from uri c#?

You can just make a System. Uri object, and use IsFile to verify it's a file, then Uri. LocalPath to extract the filename. This is much safer, as it provides you a means to check the validity of the URI as well.

How do Cshtml files work?

CSHTML files run on a web server, which generates HTML for a client web browser. CSHTML files are similar to . VBHTML (Visual Basic HTML) files. However, they use syntax that is closer to the C# language than the Visual Basic language.


1 Answers

System.IO.Path.GetFileName(Request.PhysicalPath);

like image 112
o.k.w Avatar answered Oct 17 '22 03:10

o.k.w