Objective : In the earlier posts we have already explained , how to add a custom control in the Ribbon of a sharepoint list or document library. We have also explained about the CommandUIHandlers tag and its working. So whatever custom action you want to perform when user selects any item from the Flyout anchor or when user clicks on button can be defined in the CommandUIHandlers tag.
Now we have a standard flyout anchor menu and on selection of any item, we want to open a sharepoint dialog view which in turns hosts an .aspx page. This “.aspx” page is deployed in the layouts folder of the file system.
Note : Important point to remember is that application pages will be supported only by Farm Solutions and not the SandBox solution. So when you are adding application pages always create FarmSolution
Steps :
1) Create Empty sharepoint solution (Farm Solution)
2) Add Feature in it (FlyoutAnchorElementFeature
3) Add Empty element file and name it FlyoutAnchorManifest
4) Add Mapped Layout folder and add an application Page (DemoPage.aspx)
Solution structure will look like this.
Inside DemoPage.aspx , copy the below code snippet inside “PlaceHolderMain” placeholder.
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server"> <table> <tr> <td> <asp:Label ID="lblHeaderName" runat="server" Text="Welcome to world of Microsoft technologies..."></asp:Label> </td> </tr> </table> </asp:Content> |
This can be customized as per the requirement.
Now paste the below mentioned code in your element file.
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <CustomAction Id="btnAlert" Location="CommandUI.Ribbon" RegistrationId="101" RegistrationType="List" Title="Company Profile"> <CommandUIExtension> <CommandUIDefinitions> <CommandUIDefinition Location="Ribbon.Library.Share.Controls._children"> <FlyoutAnchor Id="Ribbon.Library.Share.FlyoutAnchor" Sequence="20" LabelText="Profiles" Image32by32="_layouts/1033/images/formatmap32x32.png" TemplateAlias="o1"> <Menu Id="Ribbon.Library.Share.FlyoutAnchor.Menu"> <MenuSection Id="Ribbon.Library.Share.FlyoutAnchor.Menu.MenuSection" Sequence="10" > <Controls Id="Ribbon.Library.Share.FlyoutAnchor.Menu.MenuSection.Controls"> <Button Id="Ribbon.Library.Share.FlyoutAnchor.Menu.MenuSection.MyButton1" Sequence="0" Command="AppleCommand" LabelText="Apple Profile" TemplateAlias="o1"/> </Controls> </MenuSection> <MenuSection Id="Ribbon.Library.Share.FlyoutAnchor.Menu.MenuSection1" Sequence="20" > <Controls Id="Ribbon.Library.FlyoutAnchor.Menu.MenuSection1.Controls"> <Button Id="Ribbon.Library.FlyoutAnchor.Menu.MenuSection1.MyButton2" Sequence="0" Command="MicrosoftCommand" LabelText="Microsoft Profile" TemplateAlias="o1" /> </Controls> </MenuSection> </Menu> </FlyoutAnchor> </CommandUIDefinition> </CommandUIDefinitions> <CommandUIHandlers> <CommandUIHandler Command="AppleCommand" CommandAction="JavaScript: var options = { url: '/_Layouts/DemoSharePoint/DemoPage.aspx'}; SP.UI.ModalDialog.showModalDialog(options);"/> <CommandUIHandler Command="MicrosoftCommand" CommandAction="JavaScript: var options = { url: '/_Layouts/DemoSharePoint/DemoPage.aspx'}; SP.UI.ModalDialog.showModalDialog(options);"/> </CommandUIHandlers> </CommandUIExtension> </CustomAction> </Elements> |
In this important points to look for is
<CommandUIHandler
Command="AppleCommand"
CommandAction="JavaScript:
var options = {
url: '/_Layouts/DemoSharePoint/DemoPage.aspx'};
SP.UI.ModalDialog.showModalDialog(options);"/>
While opening the page, you can pass values through query string as well and for getting the current site context and current page details, you need to write ECMA script . Will explain more about the ECMA script in coming posts.
So this pop window will like this
As you can see in the URL section we have given the path of our demo page. So this will open the demo page as the pop up dialog window.
Your job is done J
No comments:
Post a Comment