Basics of Publishing multiple items programmatically

Challenge:

So long back posted one problem on SDN forum — http://sdn.sitecore.net/SDN5/Forum/ShowPost.aspx?PostID=45665

We have one functionality where users can select multiple items from different path for example :

/sitecore/content/A/1
/sitecore/content/A/4
/sitecore/content/A/5

Basically, we wanted to publish multiple items in one publishing Job. We asked to Sitecore support guys and they said:

In the comment for your forum post #45665 it completely correctly noted that currently in the Sitecore CMS you can publish either a single item or a whole subtree — not a list of items. You may want to use incremental publishing instead of smart publishing, because it publishes only recently changed items.

Using an incremental publishing was not an option for us. As we have Multisite Sitecore solution.

Solution:

Also, Sitecore support team suggested to use  Alex Shyba’s concept:

http://sitecoreblog.alexshyba.com/2010/07/hidden-feature-of-sitecore-62.html

Where we add item references programmatically. John is also fine with this approach on this thread : http://sdn.sitecore.net/forum//ShowPost.aspx?PostID=36069

So, you can also use it. But with few suggestions:

1.  It may affect performance. So, please test it throughly.

2. If you are using Multisite solution and have custom HTML cache clearing handler on publish:end:remote then make sure that you added same site’s items in one publish job.

Happy Multiple items publishing via code! 🙂

 

Basics of reading layout delta programmatically

Challenge:

Before few weeks, we upgrade our solution to Sitecore 6.4.1, which looks really great (Would you like to know what’s new in Sitecore 6.4? Read my earlier blog post), and supports layout delta feature. Which looks promising! (If you are new to layout delta, then please read Layout Delta articles given in Good to read section at bottom of this post)

Now, Something new comes with new challenges, and so as Layout Deltas. Before SC 6.4 we were having few functionality where we were reading Layout Renderings. But after SC 6.4 that has changed (Earlier it was storing full rendering data in item’s template under standard values __ Rendering field. But after SC 6.4 users can modify Item’s rendering details. And if user does so Item will store it’s changed values — Layout Delta only in its __ Rendering field)  Now, if you are also facing the same challenge. i.e. Wanted to read id and placeholder of all the renderings (Not only Layout Delta) and controls used in an item then this post is for you!

Solution:

We tried a lot from our side. But haven’t found any solution. Then we contacted our Sitecore experts which is Sitecore support team and as always they have given best solution to us! (So, if following solution helped you, please say thanks to Sitecore support champs!)

Following approach is useful to get full(not layout deltas) value from the item  “__Renderings” field  and shows how you can find all renderings for item presentation.


Sitecore.Data.ID id = Sitecore.Data.ID.Parse("E0CE372F-7755-4DED-A1A7-5DD4D9B0B43A"); // Replace by your Item's ID
Sitecore.Data.Items.Item item = Sitecore.Data.Database.GetDatabase("master").GetItem(id);
string l = Sitecore.Data.Fields.LayoutField.GetFieldValue(item.Fields["__Renderings"]);
LayoutDefinition layout = LayoutDefinition.Parse(l);

foreach (DeviceDefinition dev in layout.Devices)
{
if (dev != null)
{
var renderings = dev.Renderings;
if (renderings != null)
{
foreach (RenderingDefinition rend in renderings)
{
Response.Write(rend.Placeholder.ToString());
Response.Write(rend.ItemID);
Response.Write("</br>");
}
}
}
}

Good to read:

http://www.sitecore.net/community/technical-blogs/getting-to-know-sitecore/posts/2010/10/layout-deltas-what-ifs.aspx

http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2011/09/Programmatically-Update-Layout-Details-with-the-Sitecore-ASPNET-CMS.aspx

http://varunvns.wordpress.com/2012/05/10/sitecore-6-4-functionality-layout-deltas/

Happy Layout Delta Coding! 🙂

PS : Special thanks to Dmitry Belikov (Sitecore Support) for providing this suggestion and Siddhi who did all this investigation and worked on this challenge!