Mike Robbins

Sitecore Developer Blog

Follow me on GitHub


Sitecore.Services.Client Authentication

Requests to web services built upon the Sitecore.Services.Client framework need to be authenticated, in this post I will look at the authentication features built into Sitecore.Services.Client. HTTPS is required for calls to authentation services calls. As with the rest of the Sitecore framework SSC uses the ASP.net membership framework. When a authentation request is successful the .ASPXAUTH cookie is set in the response. For local testing make sure to generate a CA for your local self signed certificate. http://www.asp.net/web-api/overview/security/working-with-ssl-in-web-api  Login...
Read More


Sitecore Client Logging with JSNLog In Sitecore 8.1

With Sitecore 8.1, support has been added to log client side events. The new logging framework is built upon the standard Sitecore logging framework (which uses Log4net), allowing client side events to be logged back to the data/log folder on the delivery server. Under the hood, Sitecore client logging uses JSNLog which has been wrapped to allow Sitecore to configure it via a patch and to make use of the existing Log4net logging. Configuration All configuration for client logging is...
Read More


getFieldLabel Pipeline in Sitecore 8.1

With the release of Sitecore 8.1 a new Pipeline called getFieldLabel was added. This new pipeline allows you to inject code that can append or alter the label of a field within the Content Editor. The first thing to notice is that the pipeline accepts a GetFieldLabelArgs class for pipeline. This contains the field in question and the result. The result is a string of what will be appended to the label. Within the process method you have access to the field that your...
Read More


Sitecore SPEAK 2.0 Component vs SPEAK 1.1

With Sitecore 8.1 we get access to a brand new version of SPEAK, the shiny SPEAK 2.0. In this blog post we will look at creating a new SPEAK component using the 2.0 framework. We will compare the same SPEAK component built against version 1.0 and 2.0 to see the differences the new framework makes to development. Its worth noting that SPEAK 1.1 can still be used within Sitecore 8.1. But a SPEAK application has to be fully built against a...
Read More


Sitecore SPEAK Sitecore.app undefined in Sitecore 7.5 and Sitecore 8

Very quick post post, I know this has been catching a number of people out. Such as this Stack Overflow question. http://stackoverflow.com/questions/33020451/sitecore-speak-and-javascript/33023142#33023142 When debugging Sitecore SPEAK in Sitecore 7.x (query string ?sc_debug=1)  you could access and debug your SPEAK application in your console browser via Sitecore.app. When trying this in Sitecore 7.5 and 8 you will get "undefined" returned. In Sitecore 7.5 and 8.x Sitecore.app has been moved. The new namespace is Sitecore.Speak.app.
Read More


Sitecore.Services.Client / Entity Service Allowed Controllers

By default any Entity Service controllers you create abide by the Sitecore.Services.SecurityPolicy setting within the Sitecore.Services.Client.config. By default this is set to Sitecore.Services.Infrastructure.Web.Http.Security.ServicesLocalOnlyPolicy making the service safe and controllers only availably locally. This will cause issues if you call your controller in a live environment outside of the local environment as it wont be accessible. Allowed Controllers You can patch this setting to enable all controllers, but this is not a recommended practice, as this will open all controller endpoints to the world. Instead SSC has the...
Read More


Sitecore Content Search Computed Field Pass Custom Variables

One requirement of Content Search i've required recently, is the ability to pass in custom variables from the computed field config element. I needed this so multiple sites can use the same computed fields, but inject settings unique to that site. For example passing in the site name to generate site specific urls. Out of the box Sitecore allows you to specify a fieldName in the computed field and this populates a property within you computed field class. This is...
Read More


Sitecore SPEAK Rich Text Editor

One of the features I think has been missing from Sitecore SPEAK is a Rich Text component. This blog post is a custom Rich Text Editor I have created for Sitecore SPEAK, The underlying Rich Text Editor is provided by Tiny MCE. Sitecore SPEAK Rich Text Editor Toolbar Configuration Once the Sitecore package has been installed (Releases at the end of this page), the component is ready to be used in SPEAK applications. The Rich Text Editor will then appear when you insert...
Read More


Sitecore Razor / Glass Attribute Helper Methods Fluent API

After blogging about creating some Sitecore Glass Attribute Helper Methods (Blog Post) to help front end developers add HTML attributes to Razor / Sitecore Glass Mapper controls. I had an interesting comment from Jim Noellsch, mentioning about turning the helper classes into a Fluent API. With a Fluent API, A developer is able to chain up multiple method calls, by returning the object on each method. See an example here for a better explanation than I can give http://www.codeproject.com/Articles/640997/Fluent-interfaces-and-Method-Chaining-in-Csharp. In the context of...
Read More


Sitecore MVC Custom ID Model Binder

In this post i'll explain how to create a custom Model binder in ASP.net to allow you to pass in a Sitecore ID in your controller action. For example the controller action below accepts a Sitecore ID, however .net doesn't know how to create the ID class from the form values passed to the action.
Read More


Sitecore Content Editor Tabs In SPEAK

Within the Sitecore Content Editor, the editor section can change context based on the type of Item you are editing. For example when a media folder item is selected, the view allows you to upload media files, a template item allow you to add fields etc. These areas are called editors. Media Editor You can define and create your own custom editors within the Content Editor and specify the type of items it is applicable to. Creating the Editor To...
Read More


Sitecore Services Client ServicesApiController

With Sitecore 7.5 and now Sitecore 8, Sitecore.Services.Client (SSC) was introduced. This has given us a flexible and powerful framework for created Web API based rest services in Sitecore (See my introduction into Entity Service (part of Sitecore.Services.Client)) Entity Service is powerful, offering the repository pattern to implement functionality such as FindAll, FindByID, Create, Delete and Update for a given Entity (Model). However, what happens if you want to create a completely bespoke Web API controller and don't need any of...
Read More


Sitecore Entity Service SSC - Custom Validation Attributes

One of the exciting features of Entity Service is the flexibility to create custom validation attributes for your model. As Sitecore.Services.Client (SSC) provides a framework based approach to creating services, and both server and client side APIs, validation can take place on both server and client side. Validation on the server side is provided by standard .net validation attributes to return whether the property is valid. On the client side we can provide a JavaScript function for client side validation,...
Read More


Sitecore 8 Register Page Events

A quick Sitecore 8 code sample to demonstrate programatically registering a page event such as an internal search, or a downloaded resource. Firstly check whether the tracker is active, and there is a session. Get a reference to the current page Create an instance of PageEventData, passing in the event name (e.g. Search) and page event guid. The PageEventData exposes: itemId - The page item ID that raises the page event. Data - Data associated to the event such as...
Read More


Sitecore Entity Service SSC - IoC Configuration

Further into my series on Sitecore Entity Service within Sitecore.Services.Client, in this post I'll be look into setting up an IoC container (Structure Map in this post) for Entity Service.  In the below example of the Entity Service services controller we have an overloaded constructor creating a concrete instance of our repository. However moving towards a DI approach we want to remove the coupling to the repository and inject the dependency in instead. The first step into register our dependencies...
Read More


Sitecore Glass Attribute Helper Methods 

When using Sitecore Glass's helpers to render content in a experience editor compatible way, it is possible to add a NameValue collection to specify attributes to be appended to the HTML element. http://stackoverflow.com/questions/19587981/how-to-render-link-with-css-class-with-sitecore-glass-mapper Below I have created a few helper functions to help front end developers add html attributes such css classes and height and widths to images more easily.
Read More


Sitecore ContentSearch Language Based Search

Just a quick blog on using Sitecore content search within multilingual sites. A very basic way of achieving a multilingual search,  i've used in the past involves building a query to filter on the language from the Sitecore.Context.Language. This method is explained in a previous tweet from Jamie Little and a blog post, however a comment from Stephen Pope shed more detail on content search, where you can actually pass in a culture into the content search. https://twitter.com/stephenpope/status/493034877051490305 So how does...
Read More


Add Custom Web API Controller to Sitecore Solution

The below code snippet enables you to add a custom Web API controller to your sitecore solution. The first block of code registers the mapping for our custom controllers. Next we abort the sitecore httprequest pipeline for our custom controllers. Notice we ignore the "api/Sitecore" path, this is so we don't affect any of the existing sitecore controllers such as SPEAK, Entity Service and ItemService. Here I have created  a formatter for the Sitecore ID, this allows us to clean...
Read More


Sitecore SPEAK List Component, Custom Tile and Knockout Databinding

In this post I will walk through using the Sitecore SPEAK List Component using Knockout databinding and a custom tile to create a custom look and feel of the List component. I'm assuming you have already got a SPEAK application or understand the basics of creating a SPEAK application. (There are some great posts on Sitecore SPEAK from Martina if your new to SPEAK). Core DB SPEAK Component In the presentation details of the component add a new List Component and...
Read More


Sitecore Entity Service (SSC) Adding Paging

Recently I did a Sitecore User Group talk on Entity Service (video based on the talk available on Master Sitecore). I was asked there how you could extend Entity Service to including paging instead of using the standard GetAll() function. Using my method of extending Entity Service and its repository pattern, as explained in this blog post. This blog post will explain how to add a new custom paged function for getting all entities. The first stage is to add...
Read More


Sitecore Entity Service (SSC) Custom Controller Action

Following on from my post on the basics of Entity Service and using the JavaScript API (Entity Service in Sitecore.Service.Client), in this post I will explain how to extend Entity Service Sitecore.Services.Client (SSC) with new controller actions. Using Entity Service as standard you get the following methods: IQueryable GetAll() Entity FindById(string id) Add(Entity entity) Exists(Entity entity) Update(Entity entity) Delete(Entity entity) However Entity Service is very flexible allowing you to extend the service controller with additional actions. To add an additional...
Read More


Sitecore Fundamentals: Is Item a Content / Media Item

A quick code snippet to check whether a sitecore item is a Content item or a media item. Decompiling the above code, you can see that is simply checks whether the path contains "sitecore/content" or "sitecore/Media library" respectively. Using the above code snippet however if the sitecore API ever changes sitecore will update these methods.
Read More


Add Experience Analytics Report To Launch Pad

The launch Pad was introduced in Sitecore 7.1, however in Sitecore 8 the Launch Pad has had a major over haul. The launch pad has become a major focus and one of the central interfaces for Stecore. The Launch Pad can be extended with new SPEAK applications and analytics charts. In this blog post I will walk through adding Experience Analytics reports to the Sitecore 8 Launch Pad. As the Launch Pad is built using SPEAK to add to it...
Read More


Sitecore Replace Tokens Command

Quite often when developing Sitecore sites, as I'm optimising templates I add additional fields and tokens into the standard values. This means for already created items based on the updated template there are unexpanded $token variables in the content item. The same issue is present if you reset a content item to standard values, the tokens are adding into the content item rather than the calculated value. Therefore I've developed a new Sitecore module that adds a new command into the...
Read More


My Sitecore Modules and Contributions

Sitecore 8 Modules Sitecore 8 Wallpaper Manager A Sitecore 8 SPEAK application using Entity Service as an foundation. This application allows Sitecore users to upload new wallpapers and manage existing wallpapers. Marketplace: Sitecore Wallpaper Manager on Marketplace Source: Wallpaper Manager on GitHub Replace Token's Command A new command button for the content editor. Once pressed all tokens are expanded within the current item and replace with their calculated value. Marketplace: Replace Token Command on Marketplace Source: Token Replacement Command on GitHub Sitecore...
Read More


Entity Service Visual Studio Project Template

Recently I've been working with Entity Service in Sitecore.Services.Client in A few projects. I realised I was repeating the same process time and time again to set up the framework of Entity Service. I have therefore created a Visual Studio project template with the framework of Entity Service set up. All the references for Web API, MVC etc are included via NuGet ready to build your project on. Just bring your own Sitecore kernel and Sitecore.Service DLLs. Entity Service Project Template Entity...
Read More


Install MongoDB as a Windows service for Sitecore

To install MongoDB as a Windows service. Download and install MongoDB https://www.mongodb.org/downloads Run Command Prompt as Admin. CD to the directory containing the bin directory of your MongoDB installation. Usually "C:\Program Files\MongoDB 2.6 Standard\bin" on a standard installation of MongoDB. Run the following script to install MongDB as a service. mongod --dbpath "PathToStoreMongoDbs" --serviceName "NameYouWantToCallTheService" --logpath "PathOfWhereToStoreLogFiles" --logappend --install e.g. mongod --dbpath "C:\inetpub\wwwroot\MikeRobbins8\Databases" --serviceName "MikeRobbinsMongoDB" --logpath "C:\inetpub\wwwroot\MikeRobbins8\MongoDBLogs\mongodb.log" --logappend --install Within the services snap in you will see the MongoDB service listed where...
Read More




EntityService Sitecore.Services.Client

Sitecore.Services.Client provides a powerful and flexible method of creating Web API based services within Sitecore. Using the provided interfaces and the repository pattern means that you will be building services in a consistent way, allowing you to build more flexible services and reduce the time to develop and maintain them. Sitecore.Services.Client was introduced first in Sitecore 7.5 and supported also in Sitecore 8. Sitecore.Services.Client consists of two separate services. ItemService which allows you to work with standard Sitecore Item class....
Read More


Sitecore SPEAK: How to add Applications to Sitecore 8 Launch Pad

Sitecore SPEAK's Launch pad existed within Sitecore 7.1/7.2/7.5 but has received a major overhaul in Sitecore 8. It has become a focal point welcoming users as they login to Sitecore. Previously with Sitecore 7.x you could add shortcuts to the launch pad from within the Core database. This was done by adding application shortcut items containing the ID of the new Sitecore SPEAK application to the launch pad shortcuts folder. "/sitecore/client/Applications/Launch Pad/Page Settings/Shortcuts" Sitecore 7.x SPEAK Shortcuts With Sitecore 8, the configuration of...
Read More


Web API Sitecore ID Formatter

When using Web API, Sitecore ID's serialise with {} around the IDs. This can cause issues when working with JSON as this denotes objects encapsulation. JSON Sitecore ID's Below is a custom formatter to format Sitecore item IDs without the {}. This example has Web API registered to run alongside Web Item API. See Patrick Delancy's blog post about running Web API alongside Web Item API http://patrickdelancy.com/2013/08/sitecore-webapi-living-harmony/ The corresponding JSON public class RegisterWebApiRoute { public void Process(PipelineArgs args) { var config = GlobalConfiguration.Configuration;...
Read More


Sitecore SPEAK Visual Studio Project and Item Templates

To help developers new to Sitecore SPEAK development and speed up development for existing developers, I've created some Visual Studio templates. These help to setup new VS projects correctly for SPEAK development and add SPEAK items quickly. Ill be adding more SPEAK Visual Studio templates in the future. The first is a project template that creates a new project ready to create an SPEAK application. Sitecore SPEAK Application The second allows you to add new PageCode files directly from the add item...
Read More


Install Solr as Windows Service for Sitecore Content Search

To install Solr as a Windows service. Download and setup Solr for Sitecore.Great tutorial from Dan Solovay on this http://www.dansolovay.com/2013/05/setting-up-solr-with-sitecore-7.html Download Non Sucking Service Manager from http://nssm.cc/download Copy the nssm.exe into your solr directory. [caption id="attachment_292" href="https://mikerobbinssitecore.files.wordpress.com/2014/11/nssm1.png"> NSSM Create a bat file within the Solr/example folder. Example below, where CD is your example folder within your Solr directory. @echo off cd "C:\solr\example\" java -Xms64M -Xmx256M -jar start.jar Run Command Prompt as Admin. CD to the directory containing of your NSSM.exe Run...
Read More


Sitecore SPEAK Uploader Uploaded Item

Quite often when using the Sitecore SPEAK Uploader to upload items to the Media Library, you need to be able to access the item after upload within the JavaScript page code to work with the item. Below is an example of how to get access to the Media Item model after it has been uploaded into the Media Library. This method is only supported in Sitecore 7.1 rev. 140324 (7.1 Update-2). I raised this as a bug with Sitecore as...
Read More


Write to Web Forms Programmatically

Recently I had a requirement to capture a number of parameters from a users session and provide Sitecore administrators a way of reporting on this data and exporting the data to CSV for analysis. The reporting within WFFM was exactly what I was looking to achieve. I wondered if I could tap into this programmatically and use WFFM as my analysis and exporting tool. >Form Reports The idea is to create a new Form within WFFM and instead of adding...
Read More


Sitecore SPEAK Dialog Within Desktop

Here is a short useful tutorial for anyone wanting to add a SPEAK Dialog control within the Sitecore desktop view. Basically it uses a Sitecore sheer ui application as a proxy to point at the url of the SPEAK application. SPEAK Dialog Create a Sitecore dialog application using Sitecore rocks within the core database. SPEAK Dialog Application Create a standard application item under content / applications in the core database.Set the application field to an link pointing at the url...
Read More


Solr Search On Exact Phrase

Very brief code sample of how to perform a exact phrase match query in Solr. Using the Solr Admin's Query tool to perform a search on a field, you will notice that Solr splits each word into a token to search on. Solr Admin Query   Most of the time this is the desired functionality, however there could be times where you want to return results where the exact phrase is matched. If you perform a search wrapping quotes around...
Read More


Text Based Content Search Based On Tagging

Out of the box Sitecore offers Content Editors the power to create tags, and assign them to content items using the Tagging field in standard values. Tagging Standard Value> When analysing the indexes using LUKE, you can see that Sitecore indexes the ID's of each tag. This makes it difficult to perform a text based content search that also matches on tags. Luke Index View However Sitecore gives us the power to create computed fields in search indexes. This means...
Read More


Sitecore Item Web API XML Maintaining Sitecore SPEAK

Recently I have had a client request asking to use Sitecore Item Web API in XML format rather than JSON. Luckily within the Item Web API documentation Sitecore provide a Pipeline Processor to output XML rather than JSON.  http://sdn.sitecore.net/upload/sdn5/modules/sitecore%20item%20web%20api/sitecore_item_web_api_developer_guide_sc66-71-a4.pdf Sitecore SPEAK also makes use of the Sitecore Item Web API, but an unfortunate side effect of this code snippet is that it breaks Sitecore SPEAK as it expects JSON responses back from the web service. The code snippet below is...
Read More


Workflow RSS Feed Custom Email Action

I have worked with a number of clients that have asked why the email notifications they receive from workflow didn't reflect what is available from the RSS feed within the workbox. This seems to have been a goal of a number of developers in the past, but nothing concrete has been created to replicate the feature. There is a awesome workaround from Nick Wesselman using Rss2email. http://www.techphoria414.com/Blog/2012/April/Sitecore_Workflow_Emails_with_rss2email As part of a recent hacking session I decided to see if I...
Read More


Custom Tokens in Email Campaign Manager

Recently I had a requirement from a client where they wanted to use Sitecore Email Campaign Manager to send registration emails, containing registration details and other dynamic custom data. Here is how to create tokens within a Email Campaign message and replace them with variables in a manually triggered email. Add your token(s) into the body text of the campaign message in the format $key$, ensure that the key text is lower case. Sitecore Email Campaign Manager Custom Tokens Get...
Read More


Sitecore SPEAK Uploader Bug

Just a quick post, I have recently been playing with Sitecore SPEAK on a proof of concept for a client. I needed to use the Sitecore SPEAK uploader to upload Docx and csv files to Sitecore. However attaching and uploading these files threw a warning in the SPEAK application. It appears that in this version of Sitecore (7.1), the ImageType setting within the web.config is used to control which types of files are accepted by the SPEAK uploader component. If you want...
Read More


Publish And Send For Translate Workflow Action

Here is a useful Custom Workflow action I've written allowing a content editor to publish a content item to live while also sending its alternative language version to a translate workflow state. This allows a content item to be published to live in a single language without being held up waiting on a translation to be completed. 1. Create a workflow command to publish the content to the published state in workflow. 2. Create a new custom workflow action underneath...
Read More




Sitecore 7 Search by base templates

Quick tip, when using Sitecore 7's search API to build a general site search, you may want to return only pages rather than any other items within Sitecore. All my page items inherit from a base Item to implement page title, meta data and so on. Using linq we are able to check whether an item is based on a specific base template, to do this we need to tell Sitecore to index the base templates. By default in Sitecore...
Read More


Sitecore Data Importer / Word docx Importer

I recently had a requirement from a client to allow them to import content into Sitecore items from word docx files. After looking on the Sitecore marketplace and git hub I realised nothing existed so decided on writing a module. I did quickly realise why nobody has written one before docx files are basically zip files containing a number of files with the main document content written in XML. The document To be useful I wanted the importer to be...
Read More


Sitecore YouTube Control

A very simple and useful YouTube control for Sitecore for embedding YouTube videos. You can either specify a Sitcore item to get the YouTube ID field from, otherwise it will use the context item. Create a class using the code below Register the control in the web.config
Read More


How to use Sitecore Nuget

If you have ever used NuGet within any of your Visual Studio projects you will know how easy it is install 3rd party dependencies, update them and bring new developers onto a project, Wouldn't it be useful to take advantage of NuGet in Sitecore. With the power of Nuget and Powershell you can add files to your solution, add files to the inetpub folder containing your website and best of all insert items directly into the master database of your...
Read More


Sitecore 7 Add Single Item To Index

Recently I came up with a scenario where users were authoring content on the front end of a Sitecore site which then updated a list on the screen. The list was taking advantage of Sitecore 7's new search API, so i needed to rebuild the index to display the newly inserted item. Rebuilding the whole index for a single new item would be excessive, slow, CPU intensive and can cause issues for other users loading the page. Using JustDecompile to...
Read More




Sitecore Save and Publish Button

I've noticed a common question with teaching new content editors how to create and publish content in Sitecore. "I've created my content and saved it, how do i get the content live on the site" As we know saving content only writes the item to the Master database so the content appears in a draft status. The content editor then needs to publish the content to the web database for it to appear on the web site. Some Sitecore instances...
Read More


Sitecore extension methods

Over the past year or so, in my spare time I've been building a code library for sitecore 6.X and Sitecore 7 more recently. I've built up a big list of Sitecore extension methods so I thought I'd share some of my favorites. Feel free to comment with your own. Sitecore 7 Indexing public static void AddItemToIndex(this Item item, string indexName) { var tempItem = (SitecoreIndexableItem)item; ContentSearchManager.GetIndex(indexName).Refresh(tempItem); }
Read More


Sitecore ContentSearch exclude standard values

Using the SearchContext class within Sitecore the result collection brings back the standard values item along with any items that are matched. To solve this problem you can add a computed field to the Lucene index to return a bool property to Linq to say whether the item is a standard value of not. This means you can search and exclude standard values like this. context.GetQueryable<ClassName>().Where(i => i.TemplateId == DataAccess.GlobalItems.CarTemplate.ID && !i.IsStandardValue).ToList(); Add the following tag to the AddComputedIndexField section...
Read More