How to get current page file name?http://forums.asp.net/t/318949.aspx/1?How+to+get+current+page+file+name+Fri, 08 Oct 2010 09:30:04 -0400318949318949http://forums.asp.net/p/318949/318949.aspx/1?How+to+get+current+page+file+name+How to get current page file name? Hi, I am trying to get the current page file name that i access to. Lets say i am at test.aspx page, i want it to return me &quot;test&quot; file name. I tried to use this.Page.toString(), it returned me &quot;ASP.test_aspx&quot; which is like half correct.... but i would like to get only &quot;test&quot;. 2nd question, this.Page.toString() will always return me in a format of ASP.[filename]_[fileextention]? If that's the case, maybe i can use splilt function to get the file name i want if there aren't any better solution than that. Thanks! regards, weihann. 2003-08-25T15:50:04-04:00319115http://forums.asp.net/p/318949/319115.aspx/1?Re+How+to+get+current+page+file+name+Re: How to get current page file name? To save some parsing you could use Request.RawUrl, you will still need to parse out the extension. You might want to consider posting an argument to the page with the data you want - then you can easily query the page for that argument. HTH JD 2003-08-25T17:44:35-04:00319474http://forums.asp.net/p/318949/319474.aspx/1?Re+How+to+get+current+page+file+name+Re: How to get current page file name? also you can use string pageName = this.Page.ToString().Substring(4,this.Page.ToString().Substring(4).Length - 5) &#43; &quot;.aspx&quot;; 2003-08-26T00:05:40-04:00322686http://forums.asp.net/p/318949/322686.aspx/1?Re+How+to+get+current+page+file+name+Re: How to get current page file name? To clarify a bit on this, the &quot;ASP.test_aspx&quot; that ToString() returns is a result of the default implementation of Object.ToString(), which is to return Object.GetType().FullName. Basically, &quot;ASP._&quot; is ASP.NET's internal format for generating strongly-typed objects based on the contents of a file. You should <i>not</i> depend on this behaviour, as it is an internal detail of ASP.NET's implementation, and is by no means guaranteed to remain the same in future versions. My advice would be to use Request.PhysicalPath to get the physical location of the requested file, then use the System.IO.Path.GetFileNameWithoutExtension() method to extract only the file's name. Hope this helps. -- Ryan Milligan 2003-08-28T18:33:30-04:002057241http://forums.asp.net/p/318949/2057241.aspx/1?Re+How+to+get+current+page+file+name+Re: How to get current page file name? <p>Try this:</p> &nbsp;<pre class="prettyprint">Path.GetFileName(request.PhysicalPath);</pre>&nbsp;<br> &nbsp; <p>&nbsp;</p> 2007-12-13T07:52:50-05:002063007http://forums.asp.net/p/318949/2063007.aspx/1?Re+How+to+get+current+page+file+name+Re: How to get current page file name? <p></p> <blockquote><span class="icon-blockquote"></span> <h4>gllort</h4> Path.GetFileName(request.PhysicalPath);</blockquote> <p></p> <p>It depends on what is the actual purpose - as many things can happen from the user request to the acual servicing of the request, you might want to use Request.PhysicalPath, you might also want to use the CurrentExecutionFilePath (this will take Server.Transfer etc into account).</p> <p>You might also be interested in the actual request (after rewrite), and use Request.Url.AbsolutePath .</p> <p>Finally (?) if you want the unmodified original use new Uri(Request.RawUrl).Absolute.Path.</p> <p>In cases where a physical path is involved, use System.IO.Path.GetFileName() and System.IO.Path.GetExtension() methods to extract parts of it, and use System.Web.VirtualPathUtility.GetFileName() and GetExtension() methjods when it's a part of an URL or is a virtual path.</p> <p>Why can't things just be simple? ;-)</p> 2007-12-17T07:00:02-05:003744148http://forums.asp.net/p/318949/3744148.aspx/1?Re+How+to+get+current+page+file+name+Re: How to get current page file name? <p>&nbsp;Thanks man. Yours worked and also worked fine too</p> 2010-03-22T13:22:05-04:003744404http://forums.asp.net/p/318949/3744404.aspx/1?Re+How+to+get+current+page+file+name+Re: How to get current page file name? <p>Hi,</p> <p>try this:</p> <p>string filename = Path.GetFileName(Request.Path);</p> <p><br> </p> <p>regards</p> <p>Robert</p> 2010-03-22T15:27:17-04:003962564http://forums.asp.net/p/318949/3962564.aspx/1?Re+How+to+get+current+page+file+name+Re: How to get current page file name? <p>I've also tried de Page.ToString() but If MS change this it won't work anymore.</p> <p><br> </p> <p>I've finally use this to get only the filename &#43; extension of the file </p> <p><br> </p> <p>string[] file = Request.CurrentExecutionFilePath.Split('/'); <br> string fileName = file[file.Length-1];</p> <p><br> </p> <p>Pretty basic, I hope this help.</p> <p>Martin.<br> </p> 2010-07-08T03:53:37-04:004049624http://forums.asp.net/p/318949/4049624.aspx/1?Re+How+to+get+current+page+file+name+Re: How to get current page file name? <p></p> <blockquote><span class="icon-blockquote"></span> <h4>kanasz.robert</h4> <p></p> <p>Hi,</p> <p>try this:</p> <p>string filename = Path.GetFileName(Request.Path);</p> <p></p> </blockquote> <blockquote><span class="icon-blockquote"></span> <h4>kanasz.robert</h4> <p></p> <p></p> <p>Hi,</p> <p>try this:</p> <p>string filename = Path.GetFileName(Request.Path);</p> <p><br> </p> <p>regards</p> <p>Robert</p> <p></p> </blockquote> <p></p> <p><br> </p> <p>Thanks a lot, it helped me!</p> <p><br> </p> 2010-08-27T19:02:03-04:004117072http://forums.asp.net/p/318949/4117072.aspx/1?Re+How+to+get+current+page+file+name+Re: How to get current page file name? <p>could be useful:</p> <p><br> </p> <p>Path.GetFileName(Request.CurrentExecutionFilePath.ToLower())</p> 2010-10-08T09:30:04-04:00