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.

Solution:


StringBuilder startItemPath = new StringBuilder(@"/");
startItemPath.Append(string.Join("/", myItemsFolder.Paths.FullPath.Split(new char[] { '/' },
StringSplitOptions.RemoveEmptyEntries).Select(x => string.Format("#{0}#", x))));

allItems = contextDb.SelectItems(“fast:” + startItemPath + “//*[@@templateid = ‘” + templateID + “‘]”).ToList();

By applying above solution. The query will contain “#” around all the words in query. It won’t create any harm for the query to execute.

If you know any other better approach then do comment below.

Happy Querying!

Share

Read More

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.

(more…)

Share

Read More

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.

(more…)

Share

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, SafeDictionary2 visited)
at Sitecore.Data.Engines.DataEngine.DataEngine_CopiedItem(Object sender, ExecutedEventArgs
1 e)
at System.EventHandler1.Invoke(Object sender, TEventArgs e)
at Sitecore.Data.Engines.EngineCommand
2.RaiseEvent[TArgs](EventHandler1 handlers, Func2 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]

(more…)

Share

Read More

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.

1. Error

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.  (more…)

Share

Read More

Using AutoMapper

Challenge:

We defined the Web-Service and were using it in an application. Web-Service returns an object or list of an object.

 

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.

Share

Read More

Working with lac users in Sitecore

Challenge:

Recently we were working on a Project which includes lac of users. Our application includes Login/Logout Mechanism – which is the base for any Ecommerce Application. Yes it is an Ecommerce Application.

 

Initially while developing a Project we were having few records around 2000. So Sitecore was performing pretty well. But as we went Live with 300000 records. Sitecore went down. It took roughly 4+ Minutes to GetAllUsers. And 5 Minutes to process all the records, compare Custom Property which was needed in our case. So it was taking around 10 Minutes to Login. It was very critical time for us to get the things done as soon as possible. With the help of Sitecore – We came to know that only best approach in this case is to go with SQL Query. And Yes – Stored Procedure did our Job. We created a Stored Procedure that does the processing which we were doing via Code. So that reduced time to less than 6 Seconds – Hurray! (Refer: https://sitecorebasics.wordpress.com/2015/11/21/sitecore-login-time-from-10-minutes-to-seconds/ for more details on this.)
Sitecore internally uses the Membership Object of Asp.Net.

(more…)

Share

Read More