Wednesday, February 11, 2015

Sitecore :- How to create new language version for all items

Hi Friends,

Today we got  some requirement for the multilingual site, the requirement was to create a new language and set the version for all the items in the content tree through the code.

Here is the sample code to achieve this task.


 var homeItemA = Sitecore.Context.Database.GetItem(Landings.HomeItem);
            var languageA = Sitecore.Globalization.Language.Parse("en-SG");//new language version

            var master = Sitecore.Configuration.Factory.GetDatabase("master");

            var allItems = master.GetItem(homeItemA.Paths.FullPath).Axes.GetDescendants();

          

            foreach (var blog in allItems)
            {
                Item ca = master.GetItem(blog.Paths.FullPath, languageA);


                using (new Sitecore.SecurityModel.SecurityDisabler())
                {
                    try
                    {
                        if (0 == ca.Versions.Count)
                        {
                            ca.Versions.AddVersion();
                        }

                     
                    }
                    catch (Exception ex)
                    {
                        ca.Editing.CancelEdit();

                    }
                }
            }

Saturday, February 7, 2015

Sitecore - Best Sitecore Team Award and key highlights.




We have been working on one of the main projects and delivered all items on time, I was leading the team and it got the best team of the year for Sitecore delivery.


  1. Don’t step in with solutions too quickly. 
  2. Everyone can help you learn something.
  3. Keep communicate and ask for are you okay or need any help
  4. Keep trying
  5. Always try new things, It will keep you motivated/excited.
  6. Be authentic and honest for work progress.


Friday, January 30, 2015

Sitecore :- Fast query to bind multiist

query:fast://sitecore/content//*[@@templateid='{D5aaCB98-3204-46FB-B107-47400AB0DEF0}']



Monday, January 5, 2015

Sitecore :- Could not find file 'obj\Debug\OldProjectName.csproj.FileListAbsolute.txt


Open your .csproj file in notepad

find "obj\Debug\OldProjectName.csproj.FileListAbsolute.txt"
remove that line and save it
open your project and try to publish it and this time you will be succeeded.

Tuesday, December 9, 2014

Sitecore: - How to use Fast Query in Sitecore



Sitecore: - How to use Fast Query in Sitecore
1)      Got to  Development Tools






2)      Xpath builder
3)      Sample data

4)      To get all record
fast:/sitecore//*
5)      To get single record main node
fast:/sitecore/*

Below are the steps to check the blog entries which have the blank date.

Step #1
                Login to Sitecore, Go to Development tool then Developer center
               
Step#2
                Go to Xpath Builder and execute the fast query to check the blank records.

               

Step#3  Query
fast://sitecore/content/Apparel/Lycra B2B Home/Blog//*[
(@@templateid = '{3A2F52BC-2434-4D0A-9D20-4315A2E97C3B}' or
@@templateid ='{17D77353-51B8-4B64-ABB3-424DDA69101D}'  or
@@templateid ='{E40B3177-6362-4240-91F9-6447066FF417}'  or
@@templateid ='{5C01A279-E6BC-488D-BDDE-F44F09BD3669}') and @Date = '']



Monday, December 1, 2014

Sitecore- Some basic operations

 //Operation # 1   /// Basic operations get userName
            var str = "Start";
            var listA = Sitecore.Context.GetUserName();
           
            // Result will be like extranet\Anonymous

           //Operation # 2   /// Get all items
            var list = Sitecore.Context.Database.Items["/sitecore/content/Jack/Our Team"];

            foreach (Item subitem in list.Children)
            {
                str = str + subitem.Name;
            }
           
            testDiv.InnerText = Convert.ToString(str);

Wednesday, November 19, 2014

Sitecore :- How to update build data through excel sheet, How to create template through code, How to add formating to HTML

using Sitecore.Data.Items;
using BusinessModules;
using Sitecore.Data.Fields;
using System.Text.RegularExpressions;
using System.Text;
using Sitecore.Data.Managers;
using Sitecore.Security.Accounts;
using System.Data.OleDb;
using HtmlAgilityPack;
using System.Text.RegularExpressions;
using System.IO;
using System.Xml;
namespace ABC.layouts
{
   
    public partial class ScriptsOnDemand : System.Web.UI.Page
    {
        private void Import()
        {
            Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master", false);
            OleDbCommand command = null;
            string con = string.Empty;

            //connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strNewPath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
            con = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\EpicCV.xls;Extended Properties='Excel 4.0;HDR=Yes;'";

            try
            {
                Sitecore.Data.Items.Item rootItem = master.GetItem("/sitecore/content/Global Content/People/A");

                List BiosItem = new List(rootItem.Axes.GetDescendants().Where(m => m.TemplateID.ToString() == "{EB65BFA3-5122-43F4-A1B0-02F430F645CA}"));

                StringBuilder sb = new StringBuilder();

                using (OleDbConnection connection = new OleDbConnection(con))
                {
                    connection.Open();
                    command = new OleDbCommand("select * from [Report1$]", connection);
                    sb.Append("");
                   
                    sb.Append(" ");
                    using (OleDbDataReader dr = command.ExecuteReader())
                    {
                        int counter = 0;
                        while (dr.Read())
                        {
                            counter = counter + 1;

                            string emailID = dr["BusinessEmail"].ToString().Trim();
                            string bioVersionName = bioVersionName = dr["lastName"].ToString().Trim() + " " + dr["FirstName"].ToString().Trim();
                            string mainBiographyNarrative = formatHTML(  dr["Bio Narrative"].ToString().Trim() );
                            string experienceNarrative = formatHTML( dr["Experience Narrative"].ToString().Trim());

                            List itemMainBioList = BiosItem.Where(x => x.Fields["Email"].ToString() == emailID).ToList();
                            foreach (Item itemMainBio in itemMainBioList)
                            {
                                sb.Append("
");
                                sb.Append(" ");
                                if (!String.IsNullOrEmpty(emailID))
                                {
                                    sb.Append(" ");
                                }
                                try
                                {
                                    if (itemMainBio.Fields["Email"] != null)
                                    {
                                        sb.Append(" ");

                                        sb.Append(" ");

                                        sb.Append(" ");
                                       
                                        TemplateItem template = master.GetTemplate("{8FFC3E2B-C6F5-4A80-913D-E2A54D02FC20}");
                                        User currentUser;
                                        string domainUser = @"sitecore\UserA";
                                        currentUser = Sitecore.Security.Accounts.User.FromName(domainUser, false);

                                        Item oldVersionItem = master.GetItem(itemMainBio.Paths.FullPath + "/Versions");

                                        if (oldVersionItem != null)
                                        {

                                            oldVersionItem.Add(bioVersionName, template);
                                            using (new UserSwitcher(currentUser))
                                            {
                                                Item versionItem = master.GetItem(itemMainBio.Paths.FullPath + "/Versions/" + bioVersionName);
                                                if (versionItem != null)
                                                {
                                                  

                                                    versionItem.Editing.BeginEdit();
                                                    versionItem.Fields["VersionName"].Value = dr["Title"].ToString().Trim();
                                                    versionItem.Fields["MainBiographyNarrative"].Value = mainBiographyNarrative;
                                                    versionItem.Fields["ExperienceNarrative"].Value = experienceNarrative;
                                                    versionItem.Fields["__Workflow"].Value = "{E534CB0A-B877-49EA-BBB1-927EBD7853FE}";                                                   
                                                    versionItem.Fields["__Workflow state"].Value = "{E2CF5329-65A0-40EE-8971-88BDE0F68574}";                                                   
                                                    versionItem.Fields["__Default workflow"].Value = "{E534CB0A-B877-49EA-BBB1-927EBD7853FE}";                                                   
                                                    versionItem.Editing.AcceptChanges();
                                                    versionItem.Editing.EndEdit();
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        sb.Append("
                                        sb.Append(" ");

                                        sb.Append(" ");
                                    }
                                }
                                catch (Exception ex)
                                {
                                    string msg = ex.Message;
                                }

                                sb.Append(" ");

                            }

                        }

                    }

                    sb.Append("
Sr. No. Name Email Id on File Sitecore Email ID Version Name Match Found
" + counter + "" + dr["lastName"].ToString().Trim() + " " + dr["FirstName"].ToString().Trim() + "" + emailID + "" + itemMainBio.Fields["Email"].ToString() + "" + bioVersionName + "" + "Yes" + "    " + "No" + "
");
                    divItemList.InnerHtml = sb.ToString();
                   
                }

            }
            catch (Exception ex)
            {
                string msg = ex.Message;
            }

        }

        private string formatHTML(string inputHTML)
        {
             try
            {
                var document = new HtmlDocument();
                document.LoadHtml(inputHTML);
                StringWriter writer = new StringWriter();

                XmlWriterSettings settings = new XmlWriterSettings();
                settings.OmitXmlDeclaration = true;
                settings.ConformanceLevel = ConformanceLevel.Fragment;
                settings.CloseOutput = false;

                var xmlWriter = XmlWriter.Create(writer, settings);
                document.OptionOutputAsXml = true;                   
                document.Save(xmlWriter);
                 var newHtml = writer.ToString();

                 return Convert.ToString(newHtml);
            }
             catch (Exception ex)
             {
                 string msg = ex.Message;
                 return msg;
                
             }

        }}