Tuesday, August 21, 2012

Create a SharePoint 2010 Custom List Definition without a Content Type

List Defition
A list definition defines a schema for a SharePoint list. It contains information on what views are being used, which columns and content types are being used, and other metadata information.
List Instance
A list instance is an instance of a specific SharePoint list definition. All of its data is stored in the relevant content database. Typically a list in SharePoint used by end users to enter and view data and it is based on a list definition.

Now after we understood what we gonna talk about, lets come to the topic. There are numerous examples of how to create list definitions that include a content type but what we will try to accomplish over here is to create a List Definition and List Template without content type.


  •  Fire up visual studio and create a new solution and select “List Definition” Project Template.
  •  Then in the “SharePoint Customization Wizard” provide the local site for debugging and select the radio option to deploy as a farm solution.
  •  Then provide the List Definition Name and select the type of List definition to use in the “List Definition Settings” wizard. Note: Also select the Checkbox “Add a List Instance for this List definition”.
  •  A new project with some files as show below will get created.
  •  Now change the details of Elements.XML file of both the List Instance and List Definition. “The Elements.xml contains general information like the Name, Description, Quick Launch, etc. Schema.xml, as the name implies, contains the actual metadata information about the List Definition/List Instance”

    Note: The Template Type of both the XML should be same. Change them to a number above 10000 and same.
  •  Now the Main Task. Open the schema.XML file and then add the fields that you want to add in your List. Like in this List I want to have 2 Fields.
    Ticket NoText
    Ticket TypeChoice

    So in the Fields section I added 2 Field
    
          
          
            
              Internal
              External
            
          
        
    
    Note: Create GUID(Highlighted in BOLD) at your own  system with the Visual Studio GUID Tool.
  •  Now to add the fields to the default instance (So that we can see the Fields when the instance is created) add the FieldRef tags in the View Field of the default View as shown below.
    
            
            main.xsl
            30
            
              
              
              
              
            
    
  •  Now the last thing and an important thing (Note as we are not using content type) hence we need to remove the content type portion of the Schema.XML file as this if present will not allow us to see the fields when we create a new form.
  •  Finally the code will look like the screenshot below.
  •  Now deploy the solution and woooooooooooh we have a List definition and List Template created for us as shown below.