Welcome to MSDN Blogs Sign in | Join | Help

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
Published Wednesday, July 26, 2006 3:05 AM by Harshawardhan Chiplonkar

Comments

# re: Pages and ListItems

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.
Thursday, July 27, 2006 8:09 AM by Serge van den Oever [Macaw]

# re: Pages and ListItems

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
Thursday, July 27, 2006 11:40 AM by Harshawardhan Chiplonkar

# 2007 MOSS Resource Links (Microsoft Office SharePoint Server)

Here is an assortment of various 2007 Microsoft Office SharePoint Server Documentation / Reference Materials...
Thursday, August 17, 2006 5:55 PM by The Boiler Room - Mark Kruger, SharePoint MVP

# 2007 MOSS Resource Links (Microsoft Office SharePoint Server)

2007 MOSS Resource Links (Microsoft Office SharePoint Server) Here is an assortment of various 2007 Microsoft

Monday, September 17, 2007 2:42 PM by The Boiler Room - Mark Kruger, Microsoft SharePoint MVP
Anonymous comments are disabled
 
Page view tracker