Pages and ListItems

The first thing you notice about MOSS is you can create custom pages that get stored in a doc library/list somewhere on the site. Most of the pages get stored in the Pages gallery. Then theres the Master Page and Page Layout gallery that houses almost all the master pages and page creation templates.

From traditional concept, the gallery is a List and the Page is a ListItem. But also, moving to the v3 concepts, the items are actually pages. So how do you get to those in both the contexts?

Traditionally the API call would have looked like:

using Microsoft.SharePoint;
...
SPSite site = new SPSite(" <Site_URL> ");
SPWeb web = site.OpenWeb(); //[OR SPWeb web = site.AllWebs[0];]
SPList masterpageGallery = web.Lists["Master Page Gallery"];
foreach(SPListItem item in masterpageGallery.Items)
{
if(item.name == "MyTestPageLayout.aspx")
{
PageLayout mypgLayout = new PageLayout(item);
// do something with the PageLayout object
}
}

Alternatively, one could use the Pulishing namespaces.

using Microsoft.SharePoint.Publishing;
...
SPSite site = new SPSite(" <Site_URL> ");
PublishingSite pubSite = new PublishingSite(site);
PageLayoutCollection pgCollection = pubSite.PageLayouts;
foreach(PageLayout pg in pgCollection)
{
if(pg.Name=="MyPage.aspx")
{
//Do Something
}
}

The important thing that is highlighted here is that with MOSS there are always multiple ways of getting to the same object depending on what you want to accomplish.

-Harsh

Comments

  • Anonymous
    July 27, 2006
    Instead of looping through your PageLayoutCollection you can now use the Contains function , see http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.publishing.pagelayoutcollection.contains.aspx. Din't test it yet however.
  • Anonymous
    July 27, 2006
    Thats an alternate way to do the same. Ofcourse the actual implementation would vary on a case-to-case basis. Actually on hindsight, your finding helps better drive home the point, that in MOSS one can rest assured that there are multiple ways to achieve the same end-goal. Which path to incorporate would of course be decided on a per-case basis.
    -harsh
  • Anonymous
    August 17, 2006
    Here is an assortment of various 2007 Microsoft Office SharePoint Server Documentation / Reference Materials...
  • Anonymous
    September 17, 2007
    2007 MOSS Resource Links (Microsoft Office SharePoint Server) Here is an assortment of various 2007 Microsoft