Monday, February 16, 2009

Creating Custom Lists in SharePoint Features

One of the fastest ways to feel extremely ill as an IT worker is to read and analyze a schema.xml file associated with a SharePoint list of a SharePoint feature solution in Visual Studio. These files are thousands of lines long, cumbersome to read and make the Oracle SQL*Forms files I dealt with on my first internship in 1989 look like a piece of cake. There must be a better way to create/customize SharePoint Lists for a custom Feature. The good news is that there is and here are the steps:

 


1. On your dev SharePoint site create the custom list with all the attributes needed. For this example I'll suppose the site URL is http://moss2007vm1:81 and the new custom list is named MyCustomList.

 


2. Create an empty subdirectory in the c:\temp drive of the dev virtual machine called MyCustomListCode.

 


3. Go to a DOS prompt on the C: drive of this virtual machine and type in: CD "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN"

 


4. Type in: STSADM.EXE -o ocdexportlist -url http://moss2007vm1:81 -name "MyCustomList" -dir c:\temp\MyCustomListCode

 


5. Examine the contents of the c:\temp\MyCustomListCode directory and see that there is a schema.xml file and a few .ASPX files for the custom list. Move these files into the MyCustomList subdirectory of your Feature in Visual Studio.

 


6. Compile the Feature and build the WSP. Verify that the Feature is not activated on your site and that the custom list is not on your site. Then deploy the WSP to your dev site and activate the Feature and verify that the custom list was successfully created.

 


Suggestion: If you need to add lookups or dependencies on other features/lists this is possible with the schema.xml file and other XML config files in your solution and associated Features staplings. However I recommend adding such things AFTER the lists are created in custom code called from the Feature's FeatureActivated event handler.

No comments:

Post a Comment