Friday, September 5, 2008

Creating a Custom Action

feature.xml:

<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="GUIDWithoutBraces"
Title="Site Action Menu Custom Action"
Description="This example shows how you can add new menu to WSS Site Actions"
Version="1.0.0.0"
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="element.xml" />
</ElementManifests>
</Feature>
element.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/" >
<CustomAction Id="GUIDWithoutBraces"
GroupId="SiteActions"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="1000"
Title="Configure Site"
Description="Click on this link to configure extra settings."
Rights="ViewUsageData"
ImageUrl="_layouts/images/crtsite.gif">
<UrlAction Url="~site/_layouts/Client/CustomPage.aspx"/>
</CustomAction>

<CustomAction
Id="NEWGUID"
Location="Microsoft.SharePoint.StandardMenu"
GroupId="ActionsMenu"
ControlAssembly="Training, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0000000000000000"
ControlClass="Training.NewMenuClass">
</CustomAction>
</Elements>
CodeBehind.cs:
using System; 
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace Training
{
class NewMenuClass : System.Web.UI.WebControls.WebControl
{
protected override void CreateChildControls()
{
base.CreateChildControls();

ToolBarMenuButton siteActionsControl = ToolBarMenuButton.GetMenuControl(this);

switch (siteActionsControl.List.RootFolder.Name)
{
case "Shared Documents":
{
Controls.Add(CreateMenuItem("MenuTitle", "Description", 100, "_layouts/custompage.aspx", "_layouts/images/logo.gif"));
break;
}
}
}

private MenuItemTemplate CreateMenuItem(string Text, string Description, int Sequence, string OnClickUrl, string ImageUrl)
{
MenuItemTemplate menuItem = null;
menuItem = new MenuItemTemplate();
menuItem.ID = Guid.NewGuid().ToString();
menuItem.Text = Text;
menuItem.Description = Description;
menuItem.Sequence = Sequence;
menuItem.ClientOnClickNavigateUrl = OnClickUrl;
menuItem.ImageUrl = ImageUrl;

return menuItem;
}
}
}
Notes:
Possible values for the 'Location' attribute:

Microsoft.SharePoint.ContentTypeTemplateSettings
Microsoft.SharePoint.ContentTypeSettings
Microsoft.SharePoint.Administration.ApplicationCreated
Office.Server.ServiceProvider.Administration (Shared Services/SSP links)
Microsoft.SharePoint.ListEdit.DocumentLibrary
Microsoft.SharePoint.Workflows
NewFormToolbar
DisplayFormToolbar
EditFormToolbar
Microsoft.SharePoint.StandardMenu (SiteActions menu)
Mcrosoft.SharePoint.Create (_layouts/create.aspx )
Microsoft.SharePoint.ListEdit (To edit the properties of a list item)
EditControlBlock (image below)
Articles:
http://blogs.breezetraining.com.au/mickb/2007/03/27/MOSSHowToAddActionsToTheUserInterface.aspx

http://blog.sharepointalist.com/2009/03/moss-central-admin-application-pages-p1.html

1 comments:

Gaurav Goyal March 17, 2012 at 3:12 AM  

This is not working in SharePoint 2010. Can you please tell me how to use this in SharePoint 2010?