Tuesday, 28 May 2013

How to Add fields(Columns) in list definition ? Part III

2. We should add the following line in list definition elements.xml then change the content type id as a concat 0x0100 with new guid.(note: removed '{}' & '-') and then fieldref id is your own created field(column) id.

<ContentType ID="0x0100560CF9639C39489B845C07ED8116F6F1" Name="CutomAsaiType" Group="Custom CT" Inherits="FALSE" Description="">
    <FieldRefs>
      <FieldRef ID="{9FDF6527-1072-4751-8B15-84CA97AE7CBA}"/>
    </FieldRefs>
  </ContentType>

3. Replacing the following code in schema.xml
<ContentTypes>
      <ContentTypeRef ID="0x01">
        <Folder TargetName="Item" />
      </ContentTypeRef>
      <ContentTypeRef ID="0x0120" />
    </ContentTypes>
  With

<ContentTypes >
      <ContentTypeRef ID="0x0100560CF9639C39489B845C07ED8116F6F1">
      </ContentTypeRef>
    </ContentTypes>
and then change the contenttyperef id as your own list definition content type id.



4. Add the created field in view, the following way:-

<FieldRef Name="Name"></FieldRef>

 


Now you can able to deploy successfully and then you can see the list with field on the site.

If it is getting error like "A duplicate field name "Name" was found",
Solution1: You should change the field Name on list definition elements.xml, schema.xml & view and then add the same as a static name in list definition element.xml & schema.xml.

After that you are getting same error once agin,
Follow the Solution1 and then change field id as new guid.

There after you are getting error, please let me know.

1 comment: