One of the thing that sometimes annoys is Lambda Expression with IEqualityComparer. I was trying to pick items with Except Comparer from the list. After doing quick search on google found the below extension method which can be used in such scenario.
public static IEnumerable Except(this IEnumerable first, IEnumerable second, Func<TSource, TSource, bool> comparer)
{
return first.Where(x => second.Count(y => comparer(x, y)) == 0);
}
How to use:
List myItemsList = source.Except(myDeals, (x, y) => x.ID == y.ID).Take(requiredCount).ToList();
This will return the list of items except item(s) which match with an ID in myDeals.
Author: nikkipunjabi
Sitecore query with hypen or dashes
Challenge:
Sometimes your sitecore query might contains hypen or space and you get an error: “unterminated literal string in Query”. It is because the query contains an illegal character and the solution is to escape the “-“.So we need to add hash(#) around the word in the query.
Query: /sitecore/content/My Site/Event/ABC-Items
Earlier I referred the below article and implimented in one of the project:
Escaping dashes/“-” in Sitecore Queries. Datasource query Update
This is actually the nice example. But while working on another project, I applied below piece of code which I think is better and easy solution then the one given in above link.
Sitecore Experience Editor with different Site context
Challenge:
In Multi-Site Sitecore solution we allow user to load any site in Experience Editor with any Sitecore Site URL. We also provide an option to the user to create Sites on the fly. The problem we were facing was during Experience Editor. In Experience Editor you can make use of query string and get the Item based on sc_itemid. That was working absolutely fine. Now we provided an option to a user in Ribbon to change the color. Every Custom Site that user creates on the fly – each have their own fields to change the color. We were not getting the correct site because Webutil was providing the below information.
Sitecore.Web.WebUtil.GetRawUrl(): “/-/speak/request/v1/expeditor/ExperienceEditor.GenerateFieldUrl”
Speak Request URL: http://sc8.com:80/-/speak/request/v1/expeditor/ExperienceEditor.GenerateFieldUrl
Now in this request you don’t get sc_itemid – we wanted to get the actual item id (sc_itemid) based on the current Site which user has loaded in Experience Editor, so that we can show/load the correct option to change the color.
Error: Could not load file or assembly Ninject
Challenge:
Error: Could not load file or assembly ‘Ninject, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7’ or one of its dependencies. The system cannot find the file specified.
Above error started appearing suddenly in our local Sitecore (Sitecore.NET 8.1 (rev. 151207)) project. We eyed lot of articles on-line but none helped, So that is why I thought it’s better to blog this out. We investigated for couple of hours to get this fixed, may be this post saves someone’s time.
Nice way to install Sitecore Package in Local using Sitecore Rocks
Hello Folks,
Have you ever faced a problem after package installation to get the old items back?
Are you interested in looking at a good way of installing a package in local?
This post will answer both the questions.
The best approach that I liked is via Sitecore Rocks. Read More
Sitecore – CopyTo() not working?
Are you getting the below error while copying Sitecore Media Item(s) from one node to another. For example – from Canada Site to Australia Site?
13664 19:28:32 ERROR Project.WCMS.Extension.Shell.Applications.CopyProductData.SitecoreExtensions.CopyField: Error while saving copiedMediaItem in Copy Product Data Wizard [System.InvalidOperationException: An instance of Sitecore.Data.Items.Item was null. Additional information: Failed to find the root item "/".
at Sitecore.Diagnostics.Assert.IsNotNull(Object value, String message)
at Sitecore.Web.UI.HtmlControls.DataContext.GetState(Item& root, Item& folder, Item[]& selected)
at Sitecore.Web.UI.HtmlControls.DataContext.GetState(Item& root, Item& folder)
at Sitecore.Web.UI.HtmlControls.DataContext.ItemCreatedNotification(Object sender, ItemCreatedEventArgs args)
at Sitecore.Data.Events.ItemCreatedDelegate.Invoke(Object sender, ItemCreatedEventArgs args)
at Sitecore.Events.Event.RaiseItemCreated(Object sender, ItemCreatedEventArgs args)
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at Sitecore.Data.Engines.DataEngine.RaiseCreated(EventHandler`1 handlers, Item item, SafeDictionary`2 visited)
at Sitecore.Data.Engines.DataEngine.DataEngine_CopiedItem(Object sender, ExecutedEventArgs`1 e)
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at Sitecore.Data.Engines.EngineCommand`2.RaiseEvent[TArgs](EventHandler`1 handlers, Func`2 argsCreator)
at Sitecore.Data.Engines.DataCommands.CopyItemCommand.Executed()
at Sitecore.Data.Engines.EngineCommand`2.Execute()
at Sitecore.Data.Engines.DataEngine.CopyItem(Item source, Item destination, Boolean deep, String copyName, ID copyId)
at Sitecore.Data.Managers.ItemProvider.CopyItem(Item source, Item destination, Boolean deep, String copyName, ID copyId)
at Sitecore.Data.Managers.ItemManager.CopyItem(Item source, Item destination, Boolean deep, String copyName, ID copyId)
at Project.WCMS.Extension.Shell.Applications.CopyProductData.SitecoreExtensions.CopyField(Item item, Field sourceField) in \Project.WCMS.Extension\Shell\Applications\CopyProductData\CopyProductDataWizard.cs:line 982]
Sitecore Executive Dashboard Error: An error occurred while loading report data. Please try again or contact your administrator.
Are you getting the below exception in Executive Insight Dashboard then this post is for you.
Executive Insight Dashboard isn’t loading data at all. This was happening with us when we were accessing production analytics data. There was no any message in Logs. It was very confusing for us because you have no clue what is happening without logs. Read More
Using AutoMapper
Challenge:
There was already code written to do the processing once we get the response object from web-service.But when we get the object via web-service, it append the Web Service Reference Name because of which we were not able to utilize the already written code for processing that object. We believe in Re-usability as much as possible and wanted to re-utilize that code which was also used by other functions. Web-Service was returning lot of data which includes list and list of object inside the list etc.
Sitecore – Windows Store App
Hello Folks,I worked on Sitecore – Windows Store App couple of months ago. Today I got time from the busy schedule to share Store application with you.
This application isn’t published on Windows Store. But have plans to submit in Windows Store once Initial Phase is completed.
This application requires Item Web API to be enabled in your Sitecore Site.
Read More
Working with lac users in Sitecore
Challenge: