Archive

Posts Tagged ‘Visual Studio 2010’

Easiest way to create SharePoint List Definition

April 11, 2013 6 comments

Playing with SharePoint is always a bit of time consuming but worthy a lot J . Today we will learn the quickest way to create SharePoint list definition.

STEP 1:

  • Open SharePoint UI.
  • Create SharePoint List.
  • Name it.

STEP 2:

  • Create some columns using UI of SharePoint list.
  • Country and City columns are created and can be seen while adding an item in List created from UI.
  • Country is of type Single line of Text, whereas City is of Choice field with some choices in it.

STEP 3:

  • Go to List settings and Save this list as Template.

  • Give it a proper name, in my case, it’s been named as ‘DemoList’.
  • It will be saved in Template Gallery of Site Collection, Navigate to it.
  • Click on it and it will ask to download, save it on the desktop or any location from which you can access it easily.

STEP 4:

  • Access that saved .stp file as it will be saved with extention .stp , in my case it’s DemoList.stp
  • Rename it’s .stp to .cab
  • Extract it and open its manifest.xml in Visual Studio.
  • Press ctrl+f and find ‘UserLists’, under that node you will see <List
    Name … </List>

  • This is the actual SCMEA for the list which is to be used for creating list definition, copy it in notepad and close the manifest.xml

STEP 5:

  • Create New Project of SharePoint 2010 from here we will be using VS2010 and doing some tweaks in the SCHEMA.

  • Select Deploy as Farm Solution

  • Then Add ‘New Item’ and Select List Definition, Moreover name is properly, in my case I named it DemoList.

  • Provide the name of List Definition, I named it SPDemoListDefinition.
  • Select the type of List definition, Remember we created Custom List from UI and we are going to use its SCHEMA so select Custom List and press ‘Finish’

  • If Add a list Instance is clicked then an Instance from the List Definition will be created after the solution is being deployed.

Now you would have ‘SPDemoList’ List definition added in your solution.

Note: – We will be mainly updating the SCHEMA of ‘SPDemoList’.

  • Open Schema.xml and paste the Schema which as extracted earlier and pasted in notepad to Schema.xml of SPDemoList schema.xml


There are many things which are to be modified now, so don’t panic and focus on the modifications.

  • List
    Name={C560CF03-D855-4FD7-89E1-CBE3370ED0F8} : Change it to proper name of list
    which
    exists in Element.xml i.e SPDemoList
  • FeatureId={00BFEA71-DE22-43B2-A848-C05709900100} : Change it to the featureId into which list definition is being wrapped. Rename the feature properly as

    It will be shown in web features and on its activation List Definition will be created. You need to rename its title

Renamed:

  • Url=Lists/DemoList : Change the Url attribute to the proper name of list , We named it SPDemoList to it will be Url=Lists/SPDemoList
  • Find the “Views” section and add WebPartZoneID=”Main”, SetupPath=”pages\viewpage.aspx” attributes to the each View. Change Url attribute to Url=”AllItems.aspx”.
    • <View Name=”{352071D0-7C1E-4AD6-8875-8A11125CCBCF}” BaseViewID=”1″ WebPartZoneID=”Main” SetupPath=”pages\viewpage.aspx” Url=”AllItems.aspx” …>
  • Find the “<Forms>” section and replace three inner “Form” tags with the following.
    • <Form
      Type=DisplayForm
      Url=DisplayForm.aspx
      SetupPath=pages\form.aspx
      WebPartZoneID=Main/>
    • <Form
      Type=EditForm
      Url=EditForm.aspx
      SetupPath=pages\form.aspx
      WebPartZoneID=Main/>
    • <Form
      Type=NewForm
      Url=NewForm.aspx
      SetupPath=pages\form.aspx
      WebPartZoneID=Main/>

Now build and deploy the solution.

  • Create SharePoint List from SPDemoListDefinition and you would have all the fields available in that list which were in the list created with UI. Moreover fields from schema can be added too.
  • Make sure the Feature is active.

  • Now go to Lists à Create and create list from SPDemoListDefiniton

  • Here we Go J

Hope this will help you.

Advertisements