Traverse Site Hierarchy to Configure Inheritance

21 Mar

If you need to reconfigure an entire hierarchy of SPWeb inheritance properties, for navigation, master pages, or page layouts, go ahead and try something like this recursive function I'm using to iterate through all child SPWebs and enable navigation inheritance.  See my previous post if your not sure how to get your SPWeb in the first place.

        private void FixRecursive( SPWeb myWeb)


            foreach ( SPWeb web in myWeb.Webs)



                PublishingWeb pweb = PublishingWeb .GetPublishingWeb(web);

                pweb.InheritCurrentNavigation = true;               




As a side note, this snippet is from a utility that does a variety of publishing related fixes/tasks which I have been working on for the past month.  Hopefully I'll be able to get the utility itself up on the blog within the next few weeks.

Leave a Reply

Your email address will not be published. Required fields are marked *