Monday, April 16, 2012

SharePoint 2010 Table of Contents web part using javascript

One of the things I love about SharePoint is the ability to quickly create solutions utilizing the html web part or the content editor web part, lately I have been using the html web part as it is just a bit friendlier to use when adding client side code to handle tasks.

Today I have been trying to find an easy way to list all the sub sites in order to create a Table of Contents for our users, and while there are several ways you can do this without having to use code the Tree view and the actual Table of Contents web parts just were not meeting my needs, so a little javascript magic to the rescue!

Add a html web part to your page and then click the edit web part
Click the source editor button in the properties dialog box on the right
and paste in this script:


This script will loop through your sub sites and display a list of sites, I took it one step further and made each item a link that will take you to the site listed.

No comments: