Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

UPDATE:

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).

share|improve this question
    
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) –  Vedran Rasol Aug 6 '11 at 12:53

1 Answer 1

up vote 1 down vote accepted

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).

share|improve this answer
    
+1 for obvious reasons –  Vedran Rasol Sep 9 '11 at 11:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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