Monday, March 26, 2012

Get the ID of any SharePoint Wiki page

Hello _spPageContextInfo!!!
I found this little gem by viewing the source of my site spdwiki.com.  Simply running a console.dir() on this object reveals these properties:


  1. alertsEnabledtrue
  2. allowSilverlightPrompt"True"
  3. currentLanguage1033
  4. pageItemId1
  5. pageListId"{15d98081-a722-48ad-a30c-c25d4c31a228}"
  6. siteServerRelativeUrl"/"
  7. userId1
  8. webLanguage1033
  9. webServerRelativeUrl"/"
  10. webUIVersion4


I've noticed running this same inquiry on a different site, say http://www.sharepointfabian.com, the properties are different:


  1. alertsEnabledtrue
  2. allowSilverlightPrompt"True"
  3. currentLanguage1033
  4. pageListId"{a4668dd2-4dac-4cce-baf0-ddb1ea4f2d5e}"
  5. siteServerRelativeUrl"/"
  6. webLanguage1033
  7. webServerRelativeUrl"/blog"
  8. webUIVersion4


It's safe to say, this is because the latter is a blog and not a wiki.

What to make of all of this?  I'm able to display pertinent data accordingly and no longer required to rely on the text of the page name.

var pageID = _spPageContextInfo.pageItemId;

It's a much cleaner solution that just feels good.

I've been working on a commenting system for a SharePoint 2010 system.  Knowing some of these internal variables that are floating around is invaluable.  Hope you find this useful as well.

Yes Josh, I'm going to finish this finally. ;-)