November 10, 2016

Sitecore Utility - Sanitize Query

Recently i had an issue with the standard Sitecore queries on a bucket item: when an Sitecore item begin with a 0 the queries may return no results.
This is of course an issue with the items who are in a date based bucket. You may also have some unexpected results if you have some of the reserved keywords in the item name as "and", "or", "self", "children", "parent", "sibilings", ...
So, I have create a function to "sanitize" your queries before the Sitecore queries.

And an example of the SanitizeQuery: the SanitizeQuery function:
var myQuery = "/sitecore/content/TestSites/Test/09/28/15/56/*".SanitizeQuery();
var item = Sitecore.Context.ContentDatabase.SelectSingleItem(myQuery);

I would like to create a collection of utils function on github with all those kind of reusable functions. Like this you can easilly extract the functions you are interested in or the whole project.
You will find this repository here: https://github.com/VGBenjamin/Sitecore.Utility
If you have functions that you would like to share in this directory  you can of course propose it this could become a new collaborative repository.

No comments:

Post a Comment