Posted by: R Manimaran | April 8, 2011

SharePoint 2007: Shortcut to Site Features and Site Collection Features using Custom Actions with SubMenus

SharePoint 2007: Shortcut to Site Features and Site Collection Features using Custom Actions with SubMenus

If we want to access the Site Features and Site Collection features, we need to go through

Site Actions => Site Settings => Site Collection Feature (or)

Site Actions => Site Settings => Site Features

If we have some shortcut to reach here it will be good. Somewhere in SiteActions as below.

Create a Custom Actions Feature

Elements.xml


<?xml version="1.0" encoding="utf-8" ?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<CustomAction

Id="{7DA60947-7203-4140-BFD1-7264FE1D9101}"

GroupId="SiteActions"

Location="Microsoft.SharePoint.StandardMenu"

Sequence="2000"

Title="Manage Site Feature"

Description="Manage Site Features"

ImageUrl="/_layouts/Images/menuspreadsheet.gif">

<UrlAction Url="~site/_layouts/ManageFeatures.aspx"/>

</CustomAction>

<CustomAction

Id="{B3C3F214-A571-4667-AF8B-29B151EECE96}"

GroupId="SiteActions"

Location="Microsoft.SharePoint.StandardMenu"

Sequence="2001"

Title="Manage Site Collection Feature"

Description="Manage Site Collections Feature"

ImageUrl="/_layouts/Images/menuspreadsheet.gif">

<UrlAction Url="~site/_layouts/ManageFeatures.aspx?Scope=Site"/>

</CustomAction>

</Elements>

In the above, the menus are coming in a row.

If you want to have a Submenu we have use CustomAction’s ControlAssembly and ControlClass as shown below.

Step by Step:

· In Visual Studio create a new Class Library Project.

· Change the Class name to ManageFeatures

· Add reference to System.Web and Microsoft.SharePoint

· Inherit the class from System.Web.UI.WebControls.WebControl

· Override the CreateChildControls

· Add the following code.


protected override void CreateChildControls()

{

SubMenuTemplate manageFeatures = new SubMenuTemplate();

manageFeatures.Text = "Manage Features";

manageFeatures.Description = "Manage Site and Site Collection Features";

manageFeatures.ImageUrl = "/_layouts/images/MENUPIM.GIF";

MenuItemTemplate siteFeatures = new MenuItemTemplate();

siteFeatures.Text = "Site Features";

siteFeatures.Description = "Manage Site Features";

siteFeatures.ImageUrl = "/_layouts/images/menuspreadsheet.gif";

siteFeatures.ClientOnClickNavigateUrl = string.Format("{0}/_layouts/ManageFeatures.aspx", SPContext.Current.Web.Url);

manageFeatures.Controls.Add(siteFeatures);

MenuItemTemplate siteCollectionFeatures = new MenuItemTemplate();

siteCollectionFeatures.Text = "Site Collection Features";

siteCollectionFeatures.Description = "Manage Site Collection Features";

siteCollectionFeatures.ImageUrl = "/_layouts/images/menuspreadsheet.gif";

siteCollectionFeatures.ClientOnClickNavigateUrl=string.Format("{0}/_layouts/ManageFeatures.aspx?Scope=Site", SPContext.Current.Web.Url);

manageFeatures.Controls.Add(siteCollectionFeatures);

this.Controls.Add(manageFeatures);

}

· Build the Project and place the assembly in bin or Global Assembly cache.

· Add a Safe control Entry in Web.Config – Important Step (otherwise no menu will come)


<SafeControl Assembly="CustomActions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6607d8c50db6140f" Namespace="CustomActions" TypeName="*" Safe="True" />

· Create a Custom Actions using the Feature and Elements.xml

Feature.xml


<?xml version="1.0" encoding="utf-8" ?>

<Feature xmlns="http://schemas.microsoft.com/sharepoint/"

Title="Manage Features Actions"

Id="726638C1-573B-4f38-909F-D7DF338D7661"

Description="Custom Actions Items to Manage Features"

Scope="Site"

Version="1.0.0.0">

<ElementManifests>

<ElementManifest Location="Elements.xml"/>

</ElementManifests>

</Feature>

Elements.xml


<?xml version="1.0" encoding="utf-8" ?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<CustomAction

Id="{C2C4A650-A084-455d-A96B-9EF885D99343}"

Location="Microsoft.SharePoint.StandardMenu"

GroupId="SiteActions"

<strong>ControlAssembly</strong>="CustomActions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6607d8c50db6140f"

<strong>ControlClass</strong>="CustomActions.ManageFeatures">

</CustomAction>

</Elements>

· Place the Feature.xml and Elements.xml in a Folder under 12Hive/Templates/Features

· Install the feature using STSADM command and activate the Feature.

Stsadm –o installfeature –name ManageFeatures

Advertisements

Responses

  1. You left out that, in the class, you need a “using Microsoft.SharePoint.WebControls;” statement, too.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: