1

Does anyone have examples on, how to create list, add items to List Manager programatically?

1
  • how to get list by name, if not there then add it Commented Aug 27, 2017 at 9:13

1 Answer 1

5

There are 2 types of lists: Contact List and segmented list, each one has its own class to handle them.

You need a reference to: Sitecore.ListManagement.ContentSearch.dll

Contact List

//Get the manager
var listManager = Sitecore.Configuration.Factory.CreateObject("contactListManager", false) as ContactListManager;

//Create a list
ContactList list =  new ContactList()
{
    Name = name,
    Description = description,
    ParentId = new ID(parentId)
};
listManager.Create(list);

//Move the list to a folder (its parent)
listManager.MoveList(list.Id, list.ParentId.ToString());

//Finding a list by ID.
var list = listManager.FindById(listId);

Segmented List Manager

var segmentedListManager = Sitecore.Configuration.Factory.CreateObject("segmentedListManager", false) as SegmentedListManager;

All the other methods are the same.

These are the most basic operations you can do with lists, let me know if you need to do something else.

3
  • Which dll has this class ContactList?
    – Durga Bose
    Commented Jun 10, 2018 at 15:08
  • I have updated the answer: Sitecore.ListManagement.ContentSearch.dll Commented Jun 13, 2018 at 10:18
  • 1
    In later versions it's Sitecore.ListManagement.dll Commented Jun 13, 2018 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.