Featured Post

Web API Requests Series

Web API Series:  Create and Retrieve , Update and Delete , Retrieve Multiple , Associate/Disassociate , Impersonation , Run Workflows

12 August 2011

How to open a Silverlight application from the ribbon menu

In this post I am going to show you how to open a Silverlight application by clicking a custom ribbon button.

Steps:
  1. Create a new ribbon button
  2. Create the Silverlight application
  3. Create the XAP web resource
  4. Create a HTML web resource for the page that  hosts the Silverlight app
First of all let's create a new custom button, see this post.
Create your Silverlight application, if you want to use the REST endpoint see this post.
Create a Silverlight web resource and the HTML web resource.

Follow this guidelines when naming the web resources:

  1. HTML Web resource name = /MyApplicationName.html, this will result,after saving, in    customizationprefix_/MyApplicationName.html.
  2. HTML Web resource display name = MyApplicationName.html.
  3. XAP Web resource name = /ClientBin/MyApplicationName.xap, this will result,after saving, in                customizationprefix_/ClientBin/MyApplicationName.xap.
  4. XAP Web resource display name = MyApplicationName.xap.
Enjoy!


How to add a custom button in the ribbon menu.

In this post I will walk you through the process of creating a new ribbon button that will be able to open a HTML page from which we can access some crm context parameter such as language id and record id.
In this particular example I will be using the HTML page to host a Silverlight application.
First of all we need to export the solution that we want to customise, so navigate to settings-> Solutions and select the solution you want to export.
Once downloaded the solution open the customizations.xml file with your favourite editor.
Here is my customization:
<RibbonDiffXml>
        <CustomActions>
                <CustomAction Id="Imp.Form.Account.ShowHierarchy" Sequence="51" Location="Mscrm.Form.account.MainTab.ExportData.Controls._children">
                  <CommandUIDefinition>
                    <Button Id="Imp.Form.Account.ShowHierarchyButton" Image16by16="$webresource:new_Hierarchy16by16.gif" Image32by32="$webresource:new_Hierarchy32by32.gif" TemplateAlias="o1" LabelText="$LocLabels:Imp.Form.Account.ShowHierarchyTitle" ToolTipTitle="$LocLabels:Imp.Form.Account.ShowHierarchyTitle" ToolTipDescription="$LocLabels:Imp.Form.Account.ShowHierarchyTooltip" Command="Imp.Form.Account.ShowAccountHierarchyCommand" />
                  </CommandUIDefinition>
            </CustomAction>
                </CustomActions>
                <Templates>
                  <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
                </Templates>
                <CommandDefinitions>
                <CommandDefinition Id="Imp.Form.Account.ShowAccountHierarchyCommand">
                  <EnableRules></EnableRules>
                  <DisplayRules></DisplayRules>
                  <Actions>
                    <Url Address="$webresource:new_/SilverlightFromRibbonTestPage.html" PassParams="true"></Url>
                </Actions>
                </CommandDefinition>
                </CommandDefinitions>
                <RuleDefinitions>
                  <TabDisplayRules />
                  <DisplayRules />
                  <EnableRules />
                </RuleDefinitions>
                <LocLabels>
                <LocLabel Id="Imp.Form.Account.ShowHierarchyTooltip">
                    <Titles>
                      <Title languagecode="1033" description="This will open a HTML page hosting a Silverlight application." />
                    </Titles>
                </LocLabel>
                <LocLabel Id="Imp.Form.Account.ShowHierarchyTitle">
            <Titles>
              <Title languagecode="1033" description="Open Page" />
            </Titles>
        </LocLabel>
        </LocLabels>
      </RibbonDiffXml>

Import the new customization.xml file and if you don't have any error you should be able to see a new button on the account form.









Hope you find this post useful.
Cheers , Luciano.