Custom Actions in WSS 3 / MOSS 2007 - Part 1
Something that really frustrates my about WSS 3 and MOSS 2007 is the lack of documentation on alot of the object model as well as some of the CAML. One of the areas that really wasn't very helpful at all was the section on custom actions, so I thought I would write this post.
To begin with, just a quick introduction...custom actions in SharePoint simply refer to the buttons (such as in the "Site Actions" menu) and some of the menus across the site (such as in "Site Settings"). The best way to deploy these custom actions is definitley through a Feature. This post will show the simple way to display these custom actions. In the next post I will show how to use custom controls for the menu buttons.
Anyways, onto the code (or XML in this case)!
In the first example, I will create a custom action for the "Site Actions" menu.
To do this (and for the sake of the rest of the examples) we will begin with creating our feature manifest. Here it is:
<?xml version="1.0" encoding="utf-8"?>
<Feature Id="65245A4A-5D65-45ea-896F-6A6A808F3C80"
Title="MyCustomActionFeature"
Description="This feature adds custom actions"
Version="1.0.0.0"
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="MyCustomActions.xml"/>
</ElementManifests>
</Feature>
Here is what the MyCustomActions.xml file looks like to add an extra item to the Site Actions menu (Note that in most of the examples below, I have just left the Url blank because these are just examples, but this would be where you put the Url of where you want to link to):
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="PeopleAndGroupsAction"
GroupId="SiteActions"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="10"
Title="People and Groups"
ImageUrl="/_layouts/images/Actionscreate.gif">
<UrlAction
Url="/_layouts/people.aspx" />
</CustomAction>
</Elements>
Here is what the MyCustomActions.xml file looks like to add another custom actions menu item to the Actions menu of a list or document library.
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="MyListActionsCustomAction"
GroupId="ActionsMenu"
Location="Microsoft.SharePoint.StandardMenu"
RegistrationType="List"
Sequence="10"
Title="My Actions Custom Action">
<UrlAction
Url="~site" />
</CustomAction>
</Elements>
Here is what the MyCustomActions.xml file looks like to add another section to the Site Settings page.
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomActionGroup
Id="NewSiteSettingsGroup"
Location="Microsoft.SharePoint.SiteSettings"
Title="New Site Settings Group"
Sequence="10"
Description="" />
<CustomAction
Id="NewSiteSettingsGroupItem"
GroupId="NewSiteSettingsGroup"
Location="Microsoft.SharePoint.SiteSettings"
Sequence="10"
Title="My New Site Settings Item">
<UrlAction
Url="~site" />
</CustomAction>
</Elements>
Here is what the MyCustomActions.xml file looks like to add another section and custom action to the Central Administration page.
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomActionGroup
Id="CustomCentralAdminSection"
Location="Microsoft.SharePoint.Administration.ApplicationManagement"
Title="Custom Central Admin Section"
Sequence="10" />
<CustomAction
Id="DoSomethingInCentralAdmin"
GroupId="CustomCentralAdminSection"
Location="Microsoft.SharePoint.Administration.ApplicationManagement"
Sequence="10"
Title="Do Something In Central Admin">
<UrlAction
Url="" />
</CustomAction>
</Elements>
As you can see, adding these actions is very easy. If you want to add a group like in the Site Settings and Central Admin examples, all you have to do is add the CustomActionGroup element and then use that ID for the GroupID in your CustomAction element.
There are also attributes such as RequiresSiteAdministrator and Rights which all some security trimming.
Also, if you are trying to find the appropriate value for the Location attribute, or GroupID attribute, there are a few listed in the SDK documentation. If you want more, you can simply look/search through the "Features" directory (%Program Files%\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\) for the CustomActions written by Microsoft. After all, they used the same method Ive shown above for alot of the menus and buttons you see.
Anyway, I hope you have got the idea of custom actions. In one of the posts I have coming up I will show how to use custom controls (and hence use the ControlAssembly and ControlClass attributes) to render your custom actions.
To begin with, just a quick introduction...custom actions in SharePoint simply refer to the buttons (such as in the "Site Actions" menu) and some of the menus across the site (such as in "Site Settings"). The best way to deploy these custom actions is definitley through a Feature. This post will show the simple way to display these custom actions. In the next post I will show how to use custom controls for the menu buttons.
Anyways, onto the code (or XML in this case)!
In the first example, I will create a custom action for the "Site Actions" menu.
To do this (and for the sake of the rest of the examples) we will begin with creating our feature manifest. Here it is:
<?xml version="1.0" encoding="utf-8"?>
<Feature Id="65245A4A-5D65-45ea-896F-6A6A808F3C80"
Title="MyCustomActionFeature"
Description="This feature adds custom actions"
Version="1.0.0.0"
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="MyCustomActions.xml"/>
</ElementManifests>
</Feature>
Here is what the MyCustomActions.xml file looks like to add an extra item to the Site Actions menu (Note that in most of the examples below, I have just left the Url blank because these are just examples, but this would be where you put the Url of where you want to link to):
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="PeopleAndGroupsAction"
GroupId="SiteActions"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="10"
Title="People and Groups"
ImageUrl="/_layouts/images/Actionscreate.gif">
<UrlAction
Url="/_layouts/people.aspx" />
</CustomAction>
</Elements>
Here is what the MyCustomActions.xml file looks like to add another custom actions menu item to the Actions menu of a list or document library.
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="MyListActionsCustomAction"
GroupId="ActionsMenu"
Location="Microsoft.SharePoint.StandardMenu"
RegistrationType="List"
Sequence="10"
Title="My Actions Custom Action">
<UrlAction
Url="~site" />
</CustomAction>
</Elements>
Here is what the MyCustomActions.xml file looks like to add another section to the Site Settings page.
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomActionGroup
Id="NewSiteSettingsGroup"
Location="Microsoft.SharePoint.SiteSettings"
Title="New Site Settings Group"
Sequence="10"
Description="" />
<CustomAction
Id="NewSiteSettingsGroupItem"
GroupId="NewSiteSettingsGroup"
Location="Microsoft.SharePoint.SiteSettings"
Sequence="10"
Title="My New Site Settings Item">
<UrlAction
Url="~site" />
</CustomAction>
</Elements>
Here is what the MyCustomActions.xml file looks like to add another section and custom action to the Central Administration page.
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomActionGroup
Id="CustomCentralAdminSection"
Location="Microsoft.SharePoint.Administration.ApplicationManagement"
Title="Custom Central Admin Section"
Sequence="10" />
<CustomAction
Id="DoSomethingInCentralAdmin"
GroupId="CustomCentralAdminSection"
Location="Microsoft.SharePoint.Administration.ApplicationManagement"
Sequence="10"
Title="Do Something In Central Admin">
<UrlAction
Url="" />
</CustomAction>
</Elements>
As you can see, adding these actions is very easy. If you want to add a group like in the Site Settings and Central Admin examples, all you have to do is add the CustomActionGroup element and then use that ID for the GroupID in your CustomAction element.
There are also attributes such as RequiresSiteAdministrator and Rights which all some security trimming.
Also, if you are trying to find the appropriate value for the Location attribute, or GroupID attribute, there are a few listed in the SDK documentation. If you want more, you can simply look/search through the "Features" directory (%Program Files%\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\) for the CustomActions written by Microsoft. After all, they used the same method Ive shown above for alot of the menus and buttons you see.
Anyway, I hope you have got the idea of custom actions. In one of the posts I have coming up I will show how to use custom controls (and hence use the ControlAssembly and ControlClass attributes) to render your custom actions.
Labels: Custom Actions, MOSS 2007, SharePoint, Site Actions Menu, WSS 3
6 Comments:
Great info, thanks! However, I am looking for a way to add a custom action to the "Welcome (username)" menu.
Any ideas?
By Anonymous, at 3:17 am
Great summary, thanks!
By Anonymous, at 9:15 pm
Hi.
I did as above but used the following...
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Add command to personal action menu -->
<CustomAction Id="ChangePasswordItem" GroupId="PersonalActions" Location="Microsoft.SharePoint.StandardMenu" Sequence="100" Title="Change Password" Description="Change user password.">
<UrlAction Url="~site/_layouts/Gecko/ChangePassword.aspx" />
</CustomAction>
</Elements>
By Kimoz, at 11:33 pm
Sorry. That was in response to the first comment. Excellent post :)
By Kimoz, at 11:36 pm
I am new to WSS development. Where do I place these code segments in order to have them show up on my Site Actions menu?
By Anonymous, at 1:13 am
All good stuff … My problem is I have created a feature to do this, and it works perfectly in WSS 3.0. I try it in MOSS SP1 and it never shows up either functionally or in the Site Collection Feature list. Tried it both on our test MOSS environment and our production. Disappears without a trace … Installs fine, activates fine via STSADM, shows up in some tools, but is missing in the Site Collection Feature list and most certainly doesn’t work …
Can repeat the install successfully in WSS.
Any ideas?
By Grail, at 7:57 pm
Post a Comment
<< Home