Goal
Insert a custom icon(Email icon) on the SharePoint Document Library. The Icon should show in a Custom Group.
Challange
I thought getting the Icon on the top was easy(actually it was easy to place an icon on the top). But to place the
icon in a Custom Group was a bit tough that it seems.
Follow the steps to achieve
- Open Visual Studio 2010, Create an empty SharePoint Application.
- Add a Module, Edit the Element.xml
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="EmailDocsCustom"
Location="CommandUI.Ribbon"
RegistrationType="ContentType"
RegistrationId="0x01">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.Documents.Groups._children">
<Group
Id="EmailDocsCustomGroup"
Sequence="100"
Description="E-Mail Controls"
Title="E-Mail Controls"
Template="EmailDocsCustomGroupTemplate">
<Controls Id="EmailDocsCustomGroupControl">
<Button
Id="EmailDocsCustomGroupControlButton"
Sequence="5"
Command="SimpleAlert"
Image32by32="/_layouts/1033/images/formatmap32x32.png" Image32by32Left="-448"
Image32by32Top="-128"
ToolTipTitle="Email Documents"
ToolTipDescription="Select the documents which you want to email!"
LabelText="Email Selected Documents"
TemplateAlias="o1" />
</Controls>
</Group>
</CommandUIDefinition>
<CommandUIDefinition Location="Ribbon.Templates._children">
<GroupTemplate Id="EmailDocsCustomGroupTemplate">
<Layout Title="LargeLarge">
<OverflowSection Type="OneRow" TemplateAlias="o1" DisplayMode="Large"/>
<OverflowSection Type="OneRow" TemplateAlias="o2" DisplayMode="Large"/>
</Layout>
</GroupTemplate>
</CommandUIDefinition>
<CommandUIDefinition Location="Ribbon.Documents.Scaling._children">
<MaxSize Id="Ribbon.Documents.Scaling.Custom.MaxSize" Sequence="15"
GroupId="EmailDocsCustomGroup" Size="LargeLarge" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler Command="SimpleAlert" CommandAction="javascript:OpenEmailPage();" />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
<CustomAction
Id="EmailRelatedScript"
Location="ScriptLink"
ScriptSrc ="/_layouts/WhatEvePathYouHave/EmailScript.js"/>
With the help of this script you can do manipulations on the click of the icon placed on the top ribbon.
Below is the script in EmailScript.js.
//Get the current user and add the values found in the Email settings list function OpenEmailPage() { //Gets the current Context var _ctx = new SP.ClientContext.get_current(); //Selected Items Variables var _itemIds = ""; //Get current list id var _listId = SP.ListOperation.Selection.getSelectedList(); var _listUrl = window.location.href; //get all selected list items var _selectedItems = SP.ListOperation.Selection.getSelectedItems(_ctx); //collect selected item ids for (var i = 0; i < _selectedItems.length; i++) { if (_itemIds == "") { _itemIds += _selectedItems[i].id; } else { _itemIds += "," + _selectedItems[i].id; } } alert('ListID = ' + _listId + "\nListUrl = " + _listUrl + "\nIDs=" + _itemIds); }
No comments:
Post a Comment