Friday, June 30, 2017

Accessing a parent property from a footer in a nested repeater

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="sltDesktopNavigation.ascx.cs" Inherits="SfN.layouts.Brainfacts2.sublayouts.sltDesktopNavigation" %>
<%@ import namespace="SfN.Library.Common.Util" %>
<%@ import namespace="SfN.Library.Common.Util" %>
<div class="main-navigation">
    <div class="container">
        <asp:Repeater ID="rptTopLevelDesktopNav" OnItemDataBound="rptTopLevelDesktopNav_ItemDataBound" runat="server">
            <HeaderTemplate>
                <ul class="nav navbar-nav">
            </HeaderTemplate>
            <ItemTemplate>
                <li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href=""><%#Eval("Title") %></a>
                    <div class="dropdown-menu" role="menu">
                        <div class="container">
                            <div class="nav-links">
                                <asp:Repeater ID="rptSubDesktopNav" runat="server">
                                    <HeaderTemplate>
                                        <ul>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <li class="inner-link">
                                            <a href="<%#Eval("Link") %>"><%#Eval("Title") %></a>
                                        </li>
                                    </ItemTemplate>
                                    <FooterTemplate>
                                        <li class="inner-link">
                                            <a href="<%#DataBinder.Eval(((IDataItemContainer)((Control)Container).NamingContainer.NamingContainer).DataItem, "Link")%>">See All</a>
                                        </li>
                                        </ul>
                                    </FooterTemplate>
                                </asp:Repeater>
                            </div>
                        </div>
                    </div>
                </li>
            </ItemTemplate>
            <FooterTemplate>
                </ul>
            </FooterTemplate>
        </asp:Repeater>
    </div>
</div>

<!-- END .main-navigation -->
<div>
    <a id="skip">
        <!--skip anchor-->
    </a>
</div>


=========================Code Behind======================
using SfN.Library.Common.Util;
using Sitecore.Collections;
using Sitecore.Data.Fields;
using Sitecore.Data.Items;
using System;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SfN.layouts.Brainfacts2.sublayouts
{
    public partial class sltDesktopNavigation : System.Web.UI.UserControl
    {
        private Item DesktopNavigationRoot
        {
            get { return Sitecore.Context.Database.GetItem("{4FFF139F-4736-4FE7-9B3D-26E05775FF48}"); }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            var navigationItems = from Item topLevelChild in DesktopNavigationRoot.Children
                                  where !((CheckboxField)topLevelChild.Fields["Exclude from Navigation"]).Checked
                                  && !((CheckboxField)topLevelChild.Fields["Exclude from Desktop Navigation"]).Checked
                                  select new
                                  {
                                      Title = topLevelChild.Fields["Navigation Title"],
                                      Link = SitecoreUtils.GetItemUrl(topLevelChild),
                                      Children = topLevelChild.Children
                                  };

            string url = SitecoreUtils.GetItemUrl(Sitecore.Context.Item);

            rptTopLevelDesktopNav.DataSource = navigationItems;
            rptTopLevelDesktopNav.DataBind();
        }

        protected void rptTopLevelDesktopNav_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            var dataItem = e.Item.DataItem;
            if (DataBinder.Eval(dataItem, "Children") != null)
            {
                ChildList childList = (ChildList)DataBinder.Eval(dataItem, "Children");
                var navigationSubItems = from Item child in childList
                                         where !((CheckboxField)child.Fields["Exclude from Navigation"]).Checked
                                         && !((CheckboxField)child.Fields["Exclude from Desktop Navigation"]).Checked
                                         select new
                                         {
                                             Title = child.Fields["Navigation Title"],
                                             //SeeAllLink = SitecoreUtils.GetItemUrl(child.Parent),
                                             Link = SitecoreUtils.GetItemUrl(child)
                                         };
                Repeater subDesktopNav = (Repeater)e.Item.FindControl("rptSubDesktopNav");
                subDesktopNav.DataSource = navigationSubItems;
                subDesktopNav.DataBind();

                
            }

            if (e.Item.ItemType == ListItemType.Footer && DataBinder.Eval(dataItem, "Link") != null)
            {
                ////Item parentItem = ((RepeaterItem)NamingContainer.Parent).DataItem as Item;
                //Item pItem = ((RepeaterItem)e.Item.Parent.Parent).DataItem as Item;

                
            }
        }
    }
}

Wednesday, June 28, 2017

Solr url size limit and numerous OR clauses








Predicate with OR clauses. URL got too long and sorl was erroring out.

In Jetty.xml (in Bitnami nested folder) in the http configurations add/update the following:

<Set name="requestHeaderSize">65535</Set>


2. Sitecore content tree search not working. Look in search logs. Uses a diff index, not sitecore_master_index. Disable configurations. Where is it defined that sitecore uses a diff index?


Tuesday, June 27, 2017

Page Editor renders junk json



When you access the Page Editor, if Sitecore erroneously renders content that starts similar to following:
{"commands":[{"click":"chrome:placeholder:addControl"...
Consider the following:
  • Is the page well-formed (do the layout, sublayouts and renderings open and close elements in LOFC (last-opened-first-closed) order?)
  • Ensure all attribute values include both opening and closing quote characters.
  • Does the layout contain a single <form> element?
  • Does that <form> element include the runat="server" attribute?
  • Ensure that you have the /webedit.css file appropriate for your version of Sitecore.
  • Try adding <sc:placeholder runat="server" key="webedit" /> within the <head> element (this controls where Sitecore inserts the ribbon - if it doesn't fix your issue, remove this placeholder).
  • Try with a standard Sitecore layout rather than ASP.NET master pages.

Monday, June 26, 2017

Breakpoint not set. Code is different.

Check all of these:

1. Clean, rebuild the solution
2. Delete .pdb file from the bin folder
3. Restart Visual Studio
4. If publishing/deploying with publishing profile - publish

Wednesday, June 14, 2017

Login failed for user Workgroup/machinename$

Kept getting this message. Go to Settings.Settings file and check the connection string to the database you are trying to access. If integrated security is true set it to false.

Monday, June 12, 2017

Powershell script to rename all lucene files to solr

function Get-ConfigFileFilter([string]$providerName)
{
return "^.*\." + $providerName + "\.(.+\.)?config.*$"
}

function Set-SCSearchProvider
{
    $rootPath = Read-Host "What is the path of your Sitecore instance's website folder?";
    $choice = Read-Host "(L)ucene or (S)olr?";


    $validInput = $true;
    #test that path is valid
    If (!(Test-Path -Path $rootPath))
    {
        Write-Host "The supplied path was invalid or inaccessible." -ForegroundColor Red;
        $validInput = $false;
    }
    #test that choice is valid
    ElseIf (($choice -ne "L") -and ($choice -ne "S"))
    {
        Write-Host "You must choose L or S." -ForegroundColor Red;
        $validInput = $false;
    }
   

    If ($validInput)
    {
        If (($choice -eq "L"))
        {
            Write-Host "Set to Lucene." -ForegroundColor Yellow;
            $selectedProvider = "Lucene";
            $deselectedProvider = "Solr";
        }
        ElseIf (($choice -eq "S"))
        {
            Write-Host "Set to Solr." -ForegroundColor Yellow;
            $selectedProvider = "Solr";
            $deselectedProvider = "Lucene";
        }

        #enumerate all config files to be enabled      
        $regexp = Get-ConfigFileFilter $selectedProvider
        $filesToEnable = Get-ChildItem -Recurse -File -Path $rootPath | Where-Object { $_.FullName -match $regexp }
        foreach ($file in $filesToEnable)
        {
            Write-Host $file.Name;
            if (($file.Extension -ne ".config"))
            {
                $newFileName = [io.path]::GetFileNameWithoutExtension($file.FullName);
                $newFile = Rename-Item -Path $file.FullName -NewName $newFileName -PassThru;
                Write-Host "-> " $newFile.Name -ForegroundColor Green;
            }
        }

        #enumerate all config files to be disabled
        $regexp = Get-ConfigFileFilter $deselectedProvider
        $filesToDisable = Get-ChildItem -Recurse -File -Path $rootPath | Where-Object { $_.FullName -match $regexp }
        foreach ($file in $filesToDisable)
        {
            Write-Host $file.Name;
            if ($file.Extension -eq ".config")
            {
                $newFileName = $file.Name + ".disabled";
                $newFile = Rename-Item -Path $file.FullName -NewName $newFileName -PassThru;
                Write-Host "-> " $newFile.Name -ForegroundColor Green;
            }
        }
    }
}

Set-SCSearchProvider

Wednesday, June 7, 2017

Visual SVN



https://www.visualsvn.com/visualsvn/download/

Download Tortoise SVN first. Then Visual SVN for your Visual Studio version while Visual Studio is shut down.

2. Open Visual Studio
3. There should be a new tab called Visual SVN
4. Choose 'Get code from repo' or something like that
5. Type in the url for the repo

Monday, June 5, 2017

Solr basics



Steps I had to follow to get solr going with existing cores:


1. Install solr from zip downloaded directly from apache
2. Place the cores (folders) to C:\Installs\solr-5.5.4\server\solr (or whatever the directory is where solr is downloaded)
3. Download latest JRE
4. Set up JAVA_HOME environment variable (mine is Name: JAVA_HOME Value: C:\Program Files\Java\jre1.8.0_144)
5. Make a necessary config change ()
6. In command prompt as admin go to the bin folder for solr (C:\Installs\solr-5.5.4\bin) and type in 'solr start'
7. Go to solr admin page and see your indexes

=============================


1. Weighed search results
2. Facets
3. Boosting


In CMD:

netstat -an

Net stop HTTP / Net start HTTP

sc qc http

===========

Used Bitnami to install Solr on a remote box. When prompted for a port number Solr will listen to I left it at default which was 80. After the install Solr completely overtook iis and I could no longer get to a sitecore site. I uninstalled Solr and reinstalled it with Bitnami. This time for port number I enterd 8080.

When changing site from Lucene to Solr:

1. Correct config files
2. Correct indexing configurations
3. Check return types for computed fields (stringCollection, guildCollection) if returning a list
4. In Lync statements make sure all fields are lowercased. That's how SOLR namings are.






Thursday, June 1, 2017

Rounding and Formatting Numbers



Rounding a double

ConvertToDouble(model.ClientValuationModel.ProfitAsPercentOfRevenue).ToString("0.0")
// one deciaml

ConvertToDouble(model.ClientValuationModel.ProfitAsPercentOfRevenue).ToString("0")
// no decimals

ConvertToDouble(model.ClientValuationModel.TotalAUMperClient).ToString("C0")
 // currency with no decimals


(int)Math.Round(125987.398457)
125987

(int)Math.Round(125987.998457)
125988