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