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.
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 No Text Ticket Type Choice
So in the Fields section I added 2 Field
Note: Create GUID(Highlighted in BOLD) at your own system with the Visual Studio GUID Tool.Internal External - 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.
Hemant, I appreciate the time you took to demonstrate this process, but I'm not sure of the benefit? Wouldn't it be simpler to just add the two fields (columns) and then "Save as Template"? Where's the benefit of doing it through VS2010?
ReplyDeleteIt is required in the case when we are deploying a List as part of the solution package.May be there is a list which contains some data which is to be created when the wsp has to be deployed. This will help during those process.
DeleteAnyhow the "save as Template" feature can still help u to take the fields from it so that u need not type those fields but u directly take it from the template file after conveting it to cab.
If you are trying to deploy the solution through Visual studio then can set the "deployment configuration" to "none" in your solution properties, with that it won't activate automatically your solution.
ReplyDeleteTo know more on how to achieve can also visit : http://stackoverflow.com/questions/7486252/check-if-a-list-already-exists-before-creating-it
This helped. Nice post. Thanks :)
ReplyDelete