Why do we have to enable "Target Audience" field?
To filter the data using audience in Content Query Web Part we have to enable this feature.Manually
- Go to Sharepoint Site
- Site Actions > View All Site Content
- Select the SharePoint List you want to enable target audience.
- List Settings > Audience targeting settings
- Select the check box and save.
- This will add a field name "Target Audience" in the list.
- You can now give Item level target audience.
Programmatically
- In the event receiver where you are creating a Sharepoint List.
- Just use the code given below.
#region Enable Target Audience XmlElement _fldElement = new XmlDocument().CreateElement("Field"); _fldElement.SetAttribute("ID", "{61cbb965-1e04-4273-b658-eedaa662f48d}"); _fldElement.SetAttribute("Type", "TargetTo"); _fldElement.SetAttribute("Name", "Target_x0020_Audiences"); _fldElement.SetAttribute("StaticName", "Target_x0020_Audiences"); _fldElement.SetAttribute("DisplayName", "Target Audiences"); _fldElement.SetAttribute("Required", "FALSE"); _list.Fields.AddFieldAsXml(_fldElement.OuterXml); _list.Update(); #endregion
- That should be it. See to the list if that column is there!
Thank you and hoping the blog helped you.
No comments:
Post a Comment