How to get SharePoint Page Title and URL Programmatically

In this hint, I will show How to get SharePoint Page Title and URL Programmatically?


Get SharePoint Page Title and URL Programmatically

Get the SharePoint Page Title in C#

using Microsoft.SharePoint;
void getSPTitle()
{
// to get the sharepoint page title
String Title= SPContext.Current.Item["Title"].ToString(); 
}

Get the SharePoint Page URL in C#

using Microsoft.SharePoint;
void getSPURL()
{
// to get the sharepoint page URL
String URL=System.Web.HttpContext.Current.Request.Path;
}

Get the SharePoint Page URL using “File.Url” in C#

using Microsoft.SharePoint;
void getSPURL()
{
// to get the sharepoint page URL
SPContext.Current.Web.Url + "/" + SPContext.Current.File.Url;
}

Get SharePoint Page Title and Description using JavaScript Object Model

How to get SharePoint Page Title and URL Programmatically
<script src ="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> </script>
<script type = "text/javascript">

    $(document).ready(function() {
        // Wait until SP.JS has loaded before calling getWebUserData 
        ExecuteOrDelayUntilScriptLoaded(retrieveWebSite, "sp.js");
    });

function retrieveWebSite() {
    var clientContext = new SP.ClientContext(_spPageContextInfo.siteServerRelativeUrl);
    this.oWebsite = clientContext.get_web();
    clientContext.load(this.oWebsite);
    clientContext.executeQueryAsync(
        Function.createDelegate(this, this.onQuerySucceeded),
        Function.createDelegate(this, this.onQueryFailed)
    );
}

function onQuerySucceeded(sender, args) {
    alert('Title: ' + this.oWebsite.get_title() +
        ' Description: ' + this.oWebsite.get_description());
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() +
        '\n' + args.get_stackTrace());
} 
</script>

You might also like to check SharePoint 2016: Get Current User Using JavaScript


Conclusion

In conclusion, we have provided code samples to get SharePoint Page Title and URL Programmatically using JS and C#

Applies To
  • SharePoint 2016.
  • SharePoint 2013 / 2010.
  • C# SSOM.
  • JSOM.
You might also like to read
Have a Question?

If you have any related questions, please don’t hesitate to Ask it at deBUG.to Community.

8 thoughts on “How to get SharePoint Page Title and URL Programmatically”

  1. Pingback: Bind dropdown from SharePoint List in C# | SPGeeks

  2. Pingback: Get and Set SharePoint Multiple Choice Field Value in C# | SPGeeks

  3. Hello, after reading this awesome article i am too glad
    to share my experience here with colleagues.

  4. I’ve been surfing online more than three hours as of late, but I by no means found any fascinating article like yours. It’s beautiful
    worth sufficient for me. In my opinion, if all website
    owners and bloggers made just right content material as
    you probably did, the internet shall be a lot more useful than ever before.

Leave a Reply

Scroll to Top