Does anyone have examples on, how to create list, add items to List Manager programatically?
1 Answer
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.
-
-
I have updated the answer: Sitecore.ListManagement.ContentSearch.dll Commented Jun 13, 2018 at 10:18
-
1