We take pride in your success. We let our positivity drive us, day in and out. Talk to us at Mindfire to know us more.

Software Technology Tips

Often there is a requirement of creating Lists within a SharePoint website programmatically using API calls. Described below are 2 different methods of achieving the same using C#.Net as the programming language.
In the first approach, a SharePoint List gets created using an existing custom List Template present within the List Template Gallery. This approach helps replicate a list exactly in the same structure as of the list from which the custom list template was generated.
In the second approach, a blank SharePoint List gets generated depending on the List Template Type specified during the creation process. This approach can be used to create blank lists of type Announcements, Contacts, Discussion Board, Document Library, Events, Links, Meetings, Picture Library, Survey, Tasks, etc.
using (SPSite oSPsite = new SPSite("http://Web URL"))
{
    oSPsite.AllowUnsafeUpdates = true;
 
    using (SPWeb oSPWeb = oSPsite.OpenWeb())
    {
        oSPWeb.AllowUnsafeUpdates = true;
 
        /* 1. create list from custom ListTemplate present within ListTemplateGalery */
        SPListTemplateCollection lstTemp = oSPsite.GetCustomListTemplates(oSPWeb);
        SPListTemplate template = lstTemp["custom template name"];
        oSPWeb.Lists.Add("List Name", "Description", template);
 
 
        /* 2. create list from sharepoint list content type (e.g. Links) */
        oSPWeb.Lists.Add("List Name", "Description", SPListTemplateType.Links);
 
        oSPWeb.AllowUnsafeUpdates = false;
    }
 
    oSPsite.AllowUnsafeUpdates = false;
}


Related Tags:

SharePoint

Author: Kaushik Mohanty

top

Related Pages

  • SharePoint  Customization Gurus
  • SharePoint Development Projects

SharePoint

Let us Connect!

privacy

copyright (c) Mindfire Solutions 2007-2012. Login