Thursday 31 March 2016

How to Get File Name without Extension?

Here we discuss about how to get current page title name?

When we use below code:


    protected void Page_Load(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(Page.Title))
        {
            string path = Path.GetFileName(Request.Path);            
        }
    } 

Example:





When you use this below code:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(Page.Title))
        {
            //To get path as a string.
            string path = Path.GetFileNameWithoutExtension(Request.Path);
            //To get and set page title.
            Page.Title = Path.GetFileNameWithoutExtension(Request.Path);
        }
    }  

Example:


No comments: