In this hint, I will show How to get SharePoint Page Title and URL Programmatically?
using Microsoft.SharePoint;
void getSPTitle()
{
// to get the sharepoint page title
String Title= SPContext.Current.Item["Title"].ToString();
}
using Microsoft.SharePoint;
void getSPURL()
{
// to get the sharepoint page URL
String URL=System.Web.HttpContext.Current.Request.Path;
}
using Microsoft.SharePoint;
void getSPURL()
{
// to get the sharepoint page URL
SPContext.Current.Web.Url + "/" + SPContext.Current.File.Url;
}
<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
- Get and Set a SharePoint Multiple Lookup Field Value Using Server Object Model C#.
- SharePoint Lookup Field Multiple Values Via C#.
- Retrieve a SharePoint Choice Field Value Using Server Object Model C#.
Have a Question?
If you have any related questions, please don’t hesitate to Ask it at deBUG.to Community.
Pingback: Get SharePoint Choice Field Value In C# | SPGeeks