Mar
9
2008

How to enable target audiences for custom content types. In custom list definition.

We often take following steps to create custom list and add it to the site

a. Create custom content types with custom site columns.

b. Create custom list definition and references custom content types.

c. Create list instance as feature and activate it on the site we want to have this custom list.

To enable audience targeting for custom content type during list instance creation. We have to add one more field reference to content type.

step 1.


<ContentType ID="ENTER_GUID_HERE"

             BaseType="ENTER_BASE_TYPE_GUID_HERE"

              Group="CONTENT_TYPE_GROUP"

             Name="Custom Content Type"

             Description="My custom content type">

            <FieldRefs>

                <!-- other custom site columns omitted -->

                <FieldRef ID="{61cbb965-1e04-4273-b658-eedaa662f48d}" Name="Target_x0020_Audiences"/>

            </FieldRefs>

</ContentType>


Above adds target audiences setting field to content type.

James Tsai .NET C# SharePoint VSTO Target Audiences Content Type

Step 2. we also have to add the following field to list definition.


<!-- List schema.xml -->

<Fields>

<!--other field refs omitted -->

<Field ID="{61cbb965-1e04-4273-b658-eedaa662f48d}"

         Type="TargetTo"

          Name="Target_x0020_Audiences"

          DisplayName="Target Audiences"

          Required="FALSE"

          StaticName="Target_x0020_Audiences"

          SourceID="http://schemas.microsoft.com/sharepoint/v3"

      />

</Fields>

After you added custom list on the site, you can see that target audiences has been enabled for content type.

James Tsai .NET C# SharePoint VSTO Target Audiences Content Type

Note: If you enable target audiences from the UI and you have more than one content types for a list. Target audiences field will be enabled only for the first content type.

You have to add target audiences field reference (step 1) to all your content types in list. For them to support target audiences.

blog comments powered by Disqus