I’m working on a project which is going to require the creation of about a hundred publishing pages which were going to have to be created by hand. I really didn’t want to have to sit there going through the UI to create all those pages so I threw together a new STSADM command that I could use via a script to create the pages: gl-createpublishingpage.
Creating publishing pages via code is pretty simple – you just use the PublishingWeb object’s GetPublishingPages() method to return back the collection of pages and then call its Add method passing in the page name and layout. From there it’s just a matter of setting the field properties.
The help for the command is shown below:
C:\>stsadm -help gl-createpublishingpage stsadm -o gl-createpublishingpage Creates a new publishing page. Parameters: -url <url to the publishing web within which to create the page> -name <the filename of the page to create (do not include the extension)> -title <the page title> -layout <the filename of the page layout to use> [-fielddata <semi-colon separated list of key value pairs: "Field1=Val1;Field2=Val2"> (use ';;' to escape semi-colons in data values)]
The following table summarizes the command and its various parameters:
|Command Name||Availability||Build Date|
|gl-createpublishingpage||MOSS 2007||Released: 9/4/2008
|Parameter Name||Short Form||Required||Description||Example Usage|
|url||Yes||The URL to the publishing web within which to create the page.||-url http://portal|
|name||n||Yes||The filename of the page to create. It is not necessary to include the extension. Do not use special characters.||-name NewPage
|title||t||Yes||The title of the page. Wrap within quotes if includes spaces.||-title "New Page"
-t "New Page"
|layout||l||Yes||The filename of the page layout to use.||-layout DefaultLayout.aspx
|fielddata||fd||No||Key/Value pairs of metadata to apply to the new page. Use the internal field name and separate multiple pairs with a semi-colon. Use the following format when setting data: "Field1=Val1;Field2=Val2".||-fielddata "PublishingContactEmailfirstname.lastname@example.org;PublishingContactName=First Last"
-fd "PublishingContactEmailemail@example.com;PublishingContactName=First Last"
The following is an example of how to add a new publishing page:
stsadm -o gl-createpublishingpage -url http://portal -name NewPage -title "New Page" -layout DefaultLayout.aspx