Deleting Publications in SDL Tridion (2013+)

In SDL Tridion (especially an implementation that has been running for several months or years) it can be tricky to remove publications from the BluePrint. There are many reason this might happen, including incorrect environment syncronization, BluePrint changes and schema/template linking changes.

Regardless of the reason, the desire to remove a publication and seeing the below warning is frustrating.

Unable to delete item in SDL Tridion dialog

An easy solution, available in SDL Tridion 2013 SP1 and above is to use the PublishedItemsFilterData class. This class allows you to do a system wide query against your implementation (with many filtering options including by Publication) for published items.

Once you've reviewed that all is as expected, simply unpublish (ensuring all Publication Targets published to are active) and then you can delete the Publication.

Here's a quick code snippet to get you started

PublishedItemsFilterData publishedItemsFilter = new PublishedItemsFilterData();

//Filter to one Publication
publishedItemsFilter.ForPublication = new LinkToPublicationData { IdRef = "tcm:0-701-1" };

//Run query
var publishedItemsForPublication = client.GetSystemWideList<IdentifiableObjectData>(publishedItemsFilter);

foreach (var item in publishedItems)
    Console.WriteLine("Item {0} with Id {1} is published in Publication", item.Title, item.Id);

    //Add any custom business logic Here

    //Unpublish if desired
    client.UnPublishAsync(new[] { item.Id }, unpubInstruction, new[] { targetId }, PublishPriority.Low, readOptions);