I'm working on a project which involves scripting, via batch files, an intranet portal. We wanted to script the creation of the various division and department sites along with several lists that would be needed in each site. Eventually these site will be turned into custom site definitions using Features and Feature Stapling to provision the lists and various files but we needed something to enable us to quickly mock up a site taxonomy and present that to stakeholders. I had lots of commands to accomplish many of the required tasks but I didn't have anything to create lists and do some basic configurations of those lists. The first command I needed is detailed here and is called gl-addlist. I'll discuss some of the other commands I created in follow-up posts.
Fortunately, creating a list via code is super simple - there's single Add method you call via the SPListCollection object which you can get from the SPWeb's List property. So turning this into a new STSADM command is as simple as getting the parameters needed and passing them into the Add method:
The help for the command is shown below:
C:\>stsadm -help gl-addlist stsadm -o gl-addlist Adds a list to a web. Parameters: -url <web url to add the list to> -urlname <the name that will appear in the URL> -title <list title> -featureid <the feature ID to which the list definition belongs> -templatetype <an integer corresponding to the list definition type> [-description <list description>] [-doctemplatetype <the ID for the document template type>]
The following table summarizes the command and its various parameters:
|Command Name||Availability||Build Date|
|gl-addlist||WSS v3, MOSS 2007||8/6/2008|
|Parameter Name||Short Form||Required||Description||Example Usage|
|url||Yes||The URL of the web to add the list to.||-url http://portal/|
|urlname||name||Yes||The text that will appear in the URL for the list. So if the web URL is http://portal and you want the list to be reached via http://portal/Lists/ListName/AllItems.aspx you would pass in "Lists/ListName" as the value.||-urlname Lists/ListName
|title||Yes||The title of the list.||-title "A New List"|
|featureid||fid||Yes||The ID of the Feature that the list is defined in. You can find this information in the 12/Template/Features/... folders. For example, the Announcements list is defined in 12/Template/Features/AnnouncementsList.||-featureid "00BFEA71-D1CE-42de-9C63-A44004CE0104"
|templatetype||type||Yes||The template type ID of the list. Like the Feature ID this information can be obtained from the 12/Template/Features/... folder. For example, the Announcements list template type ID is 104 and can be found in 12/Template/Features/AnnouncementsList/ListTemplates/Announcements.xml||-templatetype 104
|description||desc||No||A brief description of the list.||-description "This is a new list."
-desc "This is a new list."
|doctemplatetype||doc||No||A string containing the integer ID for the document template type. This value corresponds to the Type attribute value specified for a document template in the Onet.xml file of the specified site template. The following list shows the default possible values: 100 - None, 101 - Word document, 102 - SharePoint Designer Web page, 103 - Excel spreadsheet, 104 - PowerPoint presentation, 105 - Basic page, 106 - Web Part page, 130 - Data connection, 1000 - Blank form. This parameter only applies to document libraries.||-doctemplatetype 100
The following is an example of how to create an announcements list intended specifically for new promotions:
stsadm -o gl-addlist -url http://portal -urlname Lists/Promotions -title Promotions -featureid "00BFEA71-D1CE-42de-9C63-A44004CE0104" -templatetype 104 -description "This list contains all announcements related to employee promotions."