Deleting a mailing list

Deleting a single mailing list

To delete a specific mailing list, you use the NewslettersManager class. The following code deletes a mailing list with the specified IDthrough the Native API.

public void DeleteMailingList(Guid id)
{
    NewslettersManager manager = NewslettersManager.GetManager();
 
    if (manager.GetMailingLists().Where(ml => ml.Id == id).Count() > 0)
    {
        manager.DeleteMailingList(id);
    }
 
    manager.SaveChanges();
}

First, you initialize the NewslettersManager. Then, you check whether an item with the specified ID exists. Finally, you delete the mailing list by calling DeleteMailingList and save the changes.

Deleting all mailing lists

To delete all mailing lists, you use the NewslettersManager class. The following code deletes all available mailing lists through the Native API.

public void DeleteMailingList()
{
    NewslettersManager manager = NewslettersManager.GetManager();
    List<MailingList> mailingLists = manager.GetMailingLists().ToList();
 
    foreach (var mailingList in mailingLists)
    {
        manager.DeleteMailingList(mailingList.Id);
    }
 
    manager.SaveChanges();
}

First, you initialize the NewslettersManager. Then, you get all the available mailing lists. Then, you iterate the collection and delete the mailing lists one by one. Finally, you save the changes.

Next steps

+1-888-365-2779
sales@sitefinity.com

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK