I created this only because I needed to debug some issues I’ve been having with Page Layouts – try to convert a sub-site to a site collection and you’ll see what I mean :). I doubt this command will be very useful to anyone but seeing as I’ve got it coded and working there was no sense in pulling the code. The command itself, gl-enumavailablepagelayouts, is very simple – it just outputs the available page layouts by calling GetAvailablePageLayouts() from a PublishingWeb object.

I’m outputting this code in XML as I wanted to display more things than what made sense in a flat file list (I suppose someone could use the output of this command for something else). The core code is shown below:

 1string url = keyValues["url"];
 2XmlDocument xmlDoc = new XmlDocument();
 3xmlDoc.AppendChild(xmlDoc.CreateElement("PageLayouts"));
 4// I added formatting just to make the xml easier to read when looking at it via the console.
 5xmlDoc.DocumentElement.AppendChild(xmlDoc.CreateWhitespace("\r\n"));
 6 
 7using (SPSite site = new SPSite(url))
 8using (SPWeb web = site.OpenWeb())
 9{
10    PublishingWeb pubweb = PublishingWeb.GetPublishingWeb(web);
11 
12    foreach (PageLayout layout in pubweb.GetAvailablePageLayouts())
13    {
14        xmlDoc.DocumentElement.AppendChild(xmlDoc.CreateWhitespace("\t"));
15        XmlElement layoutNode = xmlDoc.CreateElement("PageLayout");
16        layoutNode.AppendChild(xmlDoc.CreateWhitespace("\r\n\t\t"));
17 
18        XmlElement node = xmlDoc.CreateElement("Name");
19        node.InnerText = layout.Name;
20        layoutNode.AppendChild(node);
21        layoutNode.AppendChild(xmlDoc.CreateWhitespace("\r\n\t\t"));
22 
23        node = xmlDoc.CreateElement("Title");
24        node.InnerText = layout.Title;
25        layoutNode.AppendChild(node);
26        layoutNode.AppendChild(xmlDoc.CreateWhitespace("\r\n\t\t"));
27 
28        node = xmlDoc.CreateElement("Id");
29        node.InnerText = layout.ListItem.ID.ToString();
30        layoutNode.AppendChild(node);
31        layoutNode.AppendChild(xmlDoc.CreateWhitespace("\r\n\t\t"));
32 
33        node = xmlDoc.CreateElement("AssociatedContentType");
34        if (layout.AssociatedContentType != null)
35            node.InnerText = layout.AssociatedContentType.Name;
36        layoutNode.AppendChild(node);
37        layoutNode.AppendChild(xmlDoc.CreateWhitespace("\r\n\t\t"));
38 
39        node = xmlDoc.CreateElement("ContentType");
40        if (layout.ListItem[FieldId.ContentType] != null)
41            node.InnerText = layout.ListItem[FieldId.ContentType].ToString();
42        layoutNode.AppendChild(node);
43        layoutNode.AppendChild(xmlDoc.CreateWhitespace("\r\n\t\t"));
44 
45        node = xmlDoc.CreateElement("Hidden");
46        if (layout.ListItem[FieldId.Hidden] != null)
47            node.InnerText = layout.ListItem[FieldId.Hidden].ToString();
48        else
49            node.InnerText = "false";
50        layoutNode.AppendChild(node);
51        layoutNode.AppendChild(xmlDoc.CreateWhitespace("\r\n\t\t"));
52 
53        node = xmlDoc.CreateElement("FileUrl");
54        if (layout.ListItem.File != null)
55            node.InnerText = layout.ListItem.File.Url;
56        layoutNode.AppendChild(node);
57        layoutNode.AppendChild(xmlDoc.CreateWhitespace("\r\n\t"));
58 
59        xmlDoc.DocumentElement.AppendChild(layoutNode);
60        xmlDoc.DocumentElement.AppendChild(xmlDoc.CreateWhitespace("\r\n"));
61    }
62}
63output += xmlDoc.OuterXml;

The syntax of the command can be seen below:

C:\>stsadm -help gl-enumavailablepagelayouts

stsadm -o gl-enumavailablepagelayouts

Returns the list of page layouts available for the given site collection.

Parameters:
        -url <site collection url>

Here’s an example of how to return the avilable page layouts for a publishing site site collection:

stsadm –o gl-enumavailablepagelayouts –url "http://intranet/"

The results of running the above command can be seen below:

  1<PageLayouts>
  2        <PageLayout>
  3                <Name>PageFromDocLayout.aspx</Name>
  4                <Title>Article page with body only</Title>
  5                <Id>24</Id>
  6                <AssociatedContentType>Article Page</AssociatedContentType>
  7                <ContentType>Page Layout</ContentType>
  8                <Hidden>false</Hidden>
  9                <FileUrl>_catalogs/masterpage/PageFromDocLayout.aspx</FileUrl>
 10        </PageLayout>
 11        <PageLayout>
 12                <Name>ArticleLeft.aspx</Name>
 13                <Title>Article page with image on left</Title>
 14                <Id>21</Id>
 15                <AssociatedContentType>Article Page</AssociatedContentType>
 16                <ContentType>Page Layout</ContentType>
 17                <Hidden>false</Hidden>
 18                <FileUrl>_catalogs/masterpage/ArticleLeft.aspx</FileUrl>
 19        </PageLayout>
 20        <PageLayout>
 21                <Name>ArticleRight.aspx</Name>
 22                <Title>Article page with image on right</Title>
 23                <Id>23</Id>
 24                <AssociatedContentType>Article Page</AssociatedContentType>
 25                <ContentType>Page Layout</ContentType>
 26                <Hidden>false</Hidden>
 27                <FileUrl>_catalogs/masterpage/ArticleRight.aspx</FileUrl>
 28        </PageLayout>
 29        <PageLayout>
 30                <Name>ArticleLinks.aspx</Name>
 31                <Title>Article page with summary links</Title>
 32                <Id>22</Id>
 33                <AssociatedContentType>Article Page</AssociatedContentType>
 34                <ContentType>Page Layout</ContentType>
 35                <Hidden>false</Hidden>
 36                <FileUrl>_catalogs/masterpage/ArticleLinks.aspx</FileUrl>
 37        </PageLayout>
 38        <PageLayout>
 39                <Name>RedirectPageLayout.aspx</Name>
 40                <Title>Redirect Page</Title>
 41                <Id>27</Id>
 42                <AssociatedContentType>Redirect Page</AssociatedContentType>
 43                <ContentType>Page Layout</ContentType>
 44                <Hidden>false</Hidden>
 45                <FileUrl>_catalogs/masterpage/RedirectPageLayout.aspx</FileUrl>
 46        </PageLayout>
 47        <PageLayout>
 48                <Name>AdvancedSearchLayout.aspx</Name>
 49                <Title>Advanced Search</Title>
 50                <Id>87</Id>
 51                <AssociatedContentType>Welcome Page</AssociatedContentType>
 52                <ContentType>Page Layout</ContentType>
 53                <Hidden>false</Hidden>
 54                <FileUrl>_catalogs/masterpage/AdvancedSearchLayout.aspx</FileUrl>
 55        </PageLayout>
 56        <PageLayout>
 57                <Name>BlankWebPartPage.aspx</Name>
 58                <Title>Blank Web Part Page</Title>
 59                <Id>28</Id>
 60                <AssociatedContentType>Welcome Page</AssociatedContentType>
 61                <ContentType>Page Layout</ContentType>
 62                <Hidden>false</Hidden>
 63                <FileUrl>_catalogs/masterpage/BlankWebPartPage.aspx</FileUrl>
 64        </PageLayout>
 65        <PageLayout>
 66                <Name>PeopleSearchResults.aspx</Name>
 67                <Title>People Search Results Page</Title>
 68                <Id>90</Id>
 69                <AssociatedContentType>Welcome Page</AssociatedContentType>
 70                <ContentType>Page Layout</ContentType>
 71                <Hidden>false</Hidden>
 72                <FileUrl>_catalogs/masterpage/PeopleSearchResults.aspx</FileUrl>
 73
 74        </PageLayout>
 75        <PageLayout>
 76                <Name>SearchMain.aspx</Name>
 77                <Title>Search Page</Title>
 78                <Id>88</Id>
 79                <AssociatedContentType>Welcome Page</AssociatedContentType>
 80                <ContentType>Page Layout</ContentType>
 81                <Hidden>false</Hidden>
 82                <FileUrl>_catalogs/masterpage/SearchMain.aspx</FileUrl>
 83        </PageLayout>
 84        <PageLayout>
 85                <Name>SearchResults.aspx</Name>
 86                <Title>Search Results Page</Title>
 87                <Id>89</Id>
 88                <AssociatedContentType>Welcome Page</AssociatedContentType>
 89                <ContentType>Page Layout</ContentType>
 90                <Hidden>false</Hidden>
 91                <FileUrl>_catalogs/masterpage/SearchResults.aspx</FileUrl>
 92        </PageLayout>
 93        <PageLayout>
 94                <Name>TabViewPageLayout.aspx</Name>
 95                <Title>Site Directory Home</Title>
 96                <Id>85</Id>
 97                <AssociatedContentType>Welcome Page</AssociatedContentType>
 98                <ContentType>Page Layout</ContentType>
 99                <Hidden>false</Hidden>
100                <FileUrl>_catalogs/masterpage/TabViewPageLayout.aspx</FileUrl>
101        </PageLayout>
102        <PageLayout>
103                <Name>WelcomeLinks.aspx</Name>
104                <Title>Welcome page with summary links</Title>
105                <Id>3</Id>
106                <AssociatedContentType>Welcome Page</AssociatedContentType>
107                <ContentType>Page Layout</ContentType>
108                <Hidden>false</Hidden>
109                <FileUrl>_catalogs/masterpage/WelcomeLinks.aspx</FileUrl>
110        </PageLayout>
111        <PageLayout>
112                <Name>WelcomeTOC.aspx</Name>
113                <Title>Welcome page with table of contents</Title>
114                <Id>26</Id>
115                <AssociatedContentType>Welcome Page</AssociatedContentType>
116                <ContentType>Page Layout</ContentType>
117                <Hidden>false</Hidden>
118                <FileUrl>_catalogs/masterpage/WelcomeTOC.aspx</FileUrl>
119        </PageLayout>
120        <PageLayout>
121                <Name>DefaultLayout.aspx</Name>
122                <Title>Welcome page with Web Part zones</Title>
123                <Id>83</Id>
124                <AssociatedContentType>Welcome Page</AssociatedContentType>
125                <ContentType>Page Layout</ContentType>
126                <Hidden>false</Hidden>
127                <FileUrl>_catalogs/masterpage/DefaultLayout.aspx</FileUrl>
128        </PageLayout>
129        <PageLayout>
130                <Name>WelcomeSplash.aspx</Name>
131                <Title>Welcome splash page</Title>
132                <Id>25</Id>
133                <AssociatedContentType>Welcome Page</AssociatedContentType>
134                <ContentType>Page Layout</ContentType>
135                <Hidden>false</Hidden>
136                <FileUrl>_catalogs/masterpage/WelcomeSplash.aspx</FileUrl>
137        </PageLayout>
138</PageLayouts>