I have a situation where a class I have is passed a PublishingPage instance and I want to enumerate any and all web part zones that are used in the Layout Page for this page.

This is proving tough.

PublishingPage has a property called Layout, which is of type PageLayout. This is different from PublishingLayoutPage which inherits (eventually) to Page which has the Zones property. This PageLayout type does not have any reference to the normal ASP.NET Page type which has the Zones property I need.

I can get an SPListItem and a SPFile from the PublishingPage.Layout property, and get the contents of the page layout in raw text form, but this can't be parsed with XmlReader as it's not valid XML (has <% tags which are invalid).

I can get an SPWeb from PublishingPage.ListItem.Web, and this can get me an SPLimitedWebPartManager, where I can get a collection of LimitedWebParts (which has Zone information) - but this won't help because at this stage of my code I have no web parts.

I'm pretty stuck, it looks like the Publishing Infrastructure is quite detached from both ASP.NET and SharePoint.


I can use the SPLimitedWebPartManager to add a dummy web part (like a new ContentEditorWebPart) to a web part zone (I have the names of the zones that are used), but when I save this out and check the page back in (and get a new SPLWPM), I can get the WebParts back but the Zone property is null (the ZoneID property is populated and correct).

  • If you can get raw data of page layout content why don't you just search for <WebPartPages:WebPartZone or why don't you first delete all <% tags and then use XMLReader? Of course it is not perfect but if you are stuck... (but you probably solved this already, I am just browsing unanswered questions) Commented Aug 6, 2011 at 12:53

1 Answer 1


I know it sounds rather crude, but I vaguely remember we did something like this once which might point you in the right direction:

Get your page layout source using GetFile:

SPFile pageLayoutFile = SPSite.RootWeb.GetFile(page.Layout.ServerRelativeUrl); string pageSource = System.Text.Encoding.UTF8.GetString(pageLayoutFile.OpenBinary());

Then do a Regex on the source string to get the WebPartZone elements (as Vedran suggests in comments).

  • +1 for obvious reasons Commented Sep 9, 2011 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.