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;
                
             }

        }}

Monday, November 17, 2014

Sitecore :- Step to setup cache in sitecore application

Below are the steps


1.  Go to “web.config” and set “DisableBrowserCaching” to false.
2. Increase and tune the size of the data, items, and prefetch caches. Bigger caches = better performance. We can change size of cache of whole Sitecore instance using below settings in web.config.


      300MB
      300MB
      5MB
      5MB
'

3. Tune the prefetch cache settings under the App_Config/Prefetch/ folder. Sample /App_Config/Prefetch/Web.Config is given below.

  300MB

4. Go to sub layout item in Sitecore and identify the items which are not changed frequently, apply cache as per below screenshot.
List of necessary sub layouts are available at “Stats” page. http://invistab2cuat.edynamic.co.in:91/sitecore/admin/stats.aspx
Example Item path:  /Sitecore/layout/Sublayouts/INVISTA/Apparel/Lycra B2C/Common/Footer
After doing below changes publish website and check the checkbox as per below screenshot.

For search, blog listing you need to check “Cacheable”, “Clear on Index Update”, “VaryByData”  and “VaryByParm” checkbox




 

Friday, November 14, 2014

Sitecore :- An integration platform with MSCRM 2015 and SharePoint 2013

Hi Folks,
Good Day!
Just for the kind information about MSCRM 2015 launch and future integration with Sitecore.
Here are some of the fruitful and research on these technologies with a collaboration and future association of “SITECORE” with MSCRM (Microsoft dynamic CRM), SharePoint and Microsoft Azure.
Microsoft Dynamics CRM 2015 (otherwise known as Vega) is here! The new exciting changes and enhancements that are coming!
As we know Sitecore is a leading web content and customer experience management solution and this is 100-percent .NET compatible and .NET developers can leverage the skills they already have, the tools they already know, and through the integration technology.
Some of the glimpse about Sitecore:-
1)    More than 150 Sitecore customers have integrated Sitecore with SharePoint. Eye Witness News (<http://ewn.co.za/>), in South Africa, uses SharePoint to manage its digital assets, with Sitecore drives the public-facing digital experience.
2)    Microsoft Dynamics CRM is relied on by 2.25 million users across 33,000 customers to manage and strengthen customer relationships.
3)    Sitecore offers out-of-the-box integration with Microsoft Dynamics CRM.
4)    More than 30 percent of Sitecore customers use Microsoft Dynamics CRM.
5)    Sitecore Azure Edition leverages the considerable advantages of Microsoft Azure for scalable, enterprise-class deployment
6)    MSN Sankei, Japan’s leading news portal, launched a new photo experience using Sitecore and Microsoft Azure. The new capability has delivered impressive stability and performance, handling more than 20 million accesses per month. The site exceeded even target traffic expectations as it became the go-to site for information on the Great East Japan Earthquake.
With Sitecore and SharePoint, We can:
·    Sitecore complements Microsoft SharePoint
·    Sitecore includes out-of-the-box integration with SharePoint
·    We can easily share content across intranets, extranets, and public-facing websites
With Sitecore and Dynamics, We can:
·    Better manage the customer experience from end to end
·    Use customer intelligence to enhance conversion rates
·    Automatically capture new leads and valuable prospect data directly into the CRM system
With Sitecore Azure Edition, We can
·    Scale websites quickly and easily to new geographies
·    Respond immediately to business needs and surges in demand
·    Enjoy low cost of entry and ongoing operations
I hope some of the information is useful for us.