Custom Ribbon Action and Set the Customize Icon to Ribbon Button in a SharePoint Hosted App

Introduction

This article explains the Custom Ribbon Action to set the Custom Image to a Ribbon button and that is absolutely awesome! I was creating a Custom Action in my SharePoint Hosted app. I wanted to add a Button into the Ribbon of any Custom List to my App Web and do some work based on List Information. I started by adding a Custom Ribbon Action.

Custom Ribbon button

create Custom action for Ribbon

ribbon listItem

You can see the following code snippet of elements.xml of the Custom Ribbon Action that will be generated for you based on your settings selected in the wizard.

selected in the wizard

Have a look at the highlighted code in the previous block. You will notice that the icon of the button is a placeholder you have the ability to change. The next screenshot shows the button with the placeholder icon:

placeholder icon

Solution:

A better workaround is to use Data URIs that is a way of embedding the actual image data in the src attribute of the img tag. The only limitation is browser support for example.

The code after applying this workaround will be like this:

applying this workaround

The following is the final output of the Customize Icon to Ribbon button.

Ribbon button

Note: There are many image data URI generators online like this one.