I was tasked with creating a custom Event List (i.e. Calendar) to be deployed as a feature. I was confused, because even though I had successfully added the additional fields to the schema.xml file, they still weren’t showing up when I tried to create a new event. I figured out that I needed to extended the base Event content type to include my new columns, if I wanted them to appear in the “new”, “view”, and “edit” screens. Here’s how I went about building my feature:

Inside my list definition Feature, I created three element files. (Each file is an XML field that begins with the Elements element.) You could probably put them in one element file, but I prefer breaking it out so it’s easier to differentiate what’s in each file.

  • Fields.xml – Contains a list of the Field elements I want to add to the event.
  • ContentTypes.xml – Contains a ContentType element. The content type ID should start with 0x0102, followed by two “00”s, followed by a new GUID. You can read about base Content Type IDs here, and creating Content Type IDs based on other Content Types here. Add FieldRef elements to the content type the correspond to the Fields you added to your Field.xml file.
  • List.xml – Contains the ListTemplate element, the refers to the list schema.

The Feature.xml will refer to all three Element Manifest files in the order listed above.

So far, this simply creates the a new Event Content Type. To add it to the new list schema, you need to add it as a ContentTypeRef element in your schema.

To put it all together, here is some sample code:

Fields.xml

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field ID="{14A2BF57-A9CA-43d9-8C92-68313B70C059}" 
  Type="Text"
  Name="MyNewField" 
  DisplayName="My New Field"
  StaticName="MyNewField" 
  SourceID="http://schemas.microsoft.com/sharepoint/v3" />
</Elements>

ContentTypes.xml

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ContentType ID="0x010200C69A624AA53E459aBCD5D652B4447EFA" Name="MyCustomEvent">
    <FieldRefs>
      <FieldRef ID="{14A2BF57-A9CA-43d9-8C92-68313B70C059}" Name="MyNewField" />
    </FieldRefs>
  </ContentType>
</Elements>

List.xml

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ListTemplate
    Name="MyNewCalendar"
    DisplayName="My New Calendar"
    BaseType="0"
    Type="8000"
    OnQuickLaunch="TRUE"
    Image="/_layouts/images/itevent.gif"
    SecurityBits="11"
    Sequence="350" />
</Elements>

Feature.xml
Element Manifest portion:

<ElementManifests>
  <ElementManifest Location="Fields.xml"/>
  <ElementManifest Location="ContentTypes.xml"/>
  <ElementManifest Location="List.xml" />
  <ElementFile Location="MyNewCalendar\schema.xml"/>
</ElementManifests>

schema.xml
The schema file is inside a folder called “MyNewCalendar” inside the Feature folder. (Note: it is important that the folder is named the same thing as the list name you specified in your ListTemplate element in your List.xml file, otherwise SharePoint will not be able to find the schema file and will throw an error when you try to create the list.)

<ContentTypes>
  <ContentTypeRef ID="0x010200C69A624AA53E459aBCD5D652B4447EFA" Name="MyCustomEvent">
    <Folder TargetName="Event" />
  </ContentTypeRef>
</ContentTypes>
About Admin

Owner of Savvy Technical Solutions

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.