add

Monday, May 18, 2009

How to cretae a new SPlist instance using the WSS object model

The following code provides the code to create a list instance. Before creating the list, the code checks to make sure a list of the same title doesn’t already exist. You will notice that the code enumerates through the lists within the current site, checking each list to see if there is a matching title. If a list with a matching title does not exist, the code in this application then creates a new instance of the Announcements list type and adds a link to the Quick Launch menu for easy access.

using System;
using Microsoft.SharePoint;

class Program {
static void Main() {
using (SPSite site = new SPSite("http://localhost")) {
using (SPWeb web = site.OpenWeb()) {
string listName = "Litware News";
SPList list = null;
foreach (SPList currentList in web.Lists) {
if (currentList.Title.Equals(listName,
StringComparison.InvariantCultureIgnoreCase)) {
list = currentList;
break;
}
}

if (list == null) {
Guid listID = web.Lists.Add(listName,
"List for big news items",
SPListTemplateType.Announcements);
list = web.Lists[listID];
list.OnQuickLaunch = true;
list.Update();
}
}
}
}
}


The code shows how to create a SPLit of announcements. We can create any List type:


Document library
Used for collaborating on documents with support for versioning, check-in and check-out, and workflow. Includes support for deep integration with Microsoft Office.

Form library
Used to store XML documents and forms for use with Microsoft Office InfoPath.

Wiki page library
Used for collaborative Web pages based on wiki pages, which are dynamically generated and collaboratively edited Web pages.

Picture library
A specialized document library enhanced for use with pictures. Includes support for slide shows, thumbnails, and simple editing through Microsoft Office Picture Manager.

Announcements
Used for simple sharing of timely news with support for expiration.

Contacts
A list for tracking people and contact information, with support for integration into Microsoft Office Outlook and other WSS-compatible contacts applications.

Discussions
A simple list for threaded discussions with support for approval and managing discussion threads.

Links
A list for managing hyperlinks.

Calendar
A list for tracking upcoming events and deadlines. Includes support for integration and synchronization with Office Outlook.

Tasks
A list of activity-based items that can integrate with workflow.

Project tasks
An enhanced tasks list with support for Gannt chart rendering and integration with Microsoft Office Project.

Issue tracking
A list for tracking issues and resolution, with support for prioritization.

Custom list
An empty list definition for extending with custom columns, or created using Microsoft Office Excel spreadsheets.

No comments: