views:

330

answers:

2

Using Sitecore 5.3, what API calls would be necessary to publish a given item? If there are multiple publication targets configured, how would you specify which target to publish to?

+1  A: 

You can find the code for Sitecore 5.3 on the following page: http://sdn.sitecore.net/Snippets/Administration/Publish%20an%20Item%20Programmatically.aspx

Alex de Groot
A: 

My code is actually for Sitecore 6 but we used almost the same code when we ran 5.3

Needlessly to say maybe but in the code we publish from Master to Web and we only publish items under the node "/sitecore/content/home/projects/ongoing"

        DateTime publishDate = DateTime.Now;
        var master = Sitecore.Configuration.Factory.GetDatabase("master");
        var targetDB = Sitecore.Configuration.Factory.GetDatabase("web");
        var pubOpts = new Sitecore.Publishing.PublishOptions(master, targetDB, Sitecore.Publishing.PublishMode.Full, Sitecore.Data.Managers.LanguageManager.GetLanguage("sv", master), publishDate);
        pubOpts.Deep = true;
        string idstr = master.Items["/sitecore/content/Home/Projects/Ongoing"].ID.ToString();
        var id = new ID(idstr);
        pubOpts.RootItem = master.Items[id];
        var pub = new Sitecore.Publishing.Publisher(pubOpts);
        Sitecore.Jobs.Job pubJob = pub.PublishAsync();
        pubJob.Start();
Zooking