Ayo Softech

Thursday, 27 June 2013

Get current page name in ASP.NET

This function can be used to retrieve the current page:s name, i.e default.aspx, hello.aspx or whatever.
public string GetCurrentPageName()
    {
        string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
        System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
        string sRet = oInfo.Name;
        return sRet;
    }

No comments:

Post a Comment