Saturday, March 19, 2016

How to invoke/Call custom Pipeline


To call the pipeline use the CorePipeline.Run method as follows:
var pipelineArgs = new MyPipelineArgs();
 pipelineArgs.DbName = master;
 pipelineArgs.Item = blogCommentItem;

 CorePipeline.Run("CustomPipeline", pipelineArgs);




Simple way to create Branch Template in Sitecore

Please follow the below steps to create branch template in Sitecore.

Step 1:
Create a folder "Region" and withing Region folder Create a simple template name "Country" with two fields "Title" and "Description".


Step 2:
Duplicate the Item and name it to "City" and "State".
Step 3:
Within "Branch" create new folder named "Region". Right click --> Insert-->New Branch -->popup will open--> choose "county" template.

Please follow the below screenshot....










Simple way to Sort Sitecore Items in the Content Editor


Right click on the item you want to sort, Just shown in below screenshot


Now you can sort Subitem like creation date,Display Name,Reverse order etc.

Creating sitecore item programmatically based on template


Creating sitecore item programmatically based on template:



    public void CreateItemBasedonTemplate()
        {
           
            using (new SecurityDisabler())
            {
                //First get the parent item from the master database
                Database masterDb = Sitecore.Configuration.Factory.GetDatabase("master");
                Item parentItem = masterDb.Items["/sitecore/content/home/MyItem"];
               
                //we need to get the template from which the item is created
                TemplateItem template = masterDb.GetTemplate("sample/sample item/My Template");
               
                //Now we can add the new item as a child to the parent
                parentItem.Add("NewItem", template);

             
            }
        }

Friday, March 4, 2016

How To Publish Item CM To CD with c# code

Very simple way to Publish any Item CM To CD using c# code
public static bool PublishItemCMTOCD(Database DbName, String ItemId)
        {
            Item item = DbName.GetItem(Sitecore.Data.ID.Parse(ItemId));
            bool flag = false;

            if (item != null)
            {
                Sitecore.Publishing.PublishOptions publishOptions =
                  new Sitecore.Publishing.PublishOptions(item.Database,
                                                         Database.GetDatabase("web"),
                                                         Sitecore.Publishing.PublishMode.SingleItem,
                                                         item.Language,
                                                         System.DateTime.Now);  
                Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions);

                // Choose where to publish from
                publisher.Options.RootItem = item;

                // Publish children as well?
                publisher.Options.Deep = true;

                // Do the publish!
                publisher.Publish();
                flag = true;
            }           

            return flag;
        }