In Umbraco 6, what is the best way to save and publish a list of nodes with ContentService?

c#, umbraco

Solution

You are correct there is no `Publish` or `SaveAndPublish` option that takes in an IEnumerable like the `Save` method. It could be handy as it could save some lines of code.

The most valid option currently to achieve what you want is to do the following.

var cs = ApplicationContext.Current.Services.ContentService;
foreach(var content in yourListOfContentItems)
{
    cs.SaveAndPublish(content);
}

Saving your list before publishing by calling `Save` method isn't really going to make any differences to you as if Umbraco detects there is new content in your list it processes each individually. And from what I can tell doing that and then calling `Publish` after is not going to save you any cycles either because the Publish method calls the same `SaveAndPublishDo` method that `SaveAndPublish` calls. So might as well go straight for the end result.

Problem

I'm writing a simple function that updates/creates nodes from an XML data-source (about 400 nodes) and I'm wondering what the best way to save and publish all the nodes is. I've noticed that you can `Save` a list of nodes but there's no `SaveAndPublish` equivalent. Should I just iterate over the list and call `SaveAndPublish` for each node or is there a better way? If there is an alternative, is there any difference in terms of performance? Any answers would be greatly appreciated!

Original source