PANVEGA’s Blog

DotNet Development, SharePoint Customizing, Silverlight, MS Infrastructure and other tips and tricks

How to Add Actions to the User Interface?

Posted by PANVEGA on October 10, 2007

This example shows how to add custom actions to various menus in SharePoint through a Feature.

  1. Create a UserInterfaceCustomActions folder within the setup directory at the following location: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES.
  2. Create your custom feature.xml file in visual studio
  3. Create a elements.xml file with for example some CustomActions. Define here elements for the various actions included within the feature. For the sake of example, the URL for each action points to an .aspx file and passes it a value that identifies the source of the request. <UrlAction Url=”/_layouts/CustomHello.aspx?ViewToolbar”/>
  4. Create a aspx with custom example code CustomHello.aspx with some URL Parameters Queries and some text when the users clicks on the Hypetlink in the CustomAction string clientQuery = Page.Request.QueryString[“ListId”];
  5. Copy the file into the Layouts in the 12 MOSS Directory. Better using your Solution.
  6. Create also a UserControl file with some simple input CustomHello.ascx
  7. Copy the file into the ControlTemplates in the 12 MOSS Directory
  8. At a command prompt to install the Feature in the deployment, activate the Feature on a specified subsite
  9. Then reset Microsoft Internet Information Services (IIS) so that the changes can take effect.
  10. To see the various custom actions that you have added, navigate to the following locations from the home page of a Web site in the site collection:
  • Click Site Actions to see the new action on the Site Actions menu.
  • Click Site Settings on the Site Actions menu to see a new action in the Look and Feel section of the Site Settings page.
  • Navigate to a document library and open each menu on the toolbar to see a new action on each menu.
  • In a document library that contains items, click the down arrow for an item to see the new action on the edit control block menu.
  • On the edit control block menu for an item, click View Properties and Edit Properties to see new actions on the Display form and Edit form toolbars.

here you find some Default Actions: http://msdn.microsoft.com/en-us/library/bb802730.aspx

Elements.xml

<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”&gt;
<!– 1. Document Library Toolbar New Menu Dropdown –>
<CustomAction Id=”UserInterfaceLightUp.DocLibNewToolbar”
RegistrationType=”List”
RegistrationId=”101″
GroupId=”NewMenu”
Rights=”ManagePermissions”
Location=”Microsoft.SharePoint.StandardMenu”
Sequence=”1000″
Title=”MY DOCLIB NEW MENU TOOLBAR BUTTON”>
<UrlAction Url=”/_layouts/LightupHello.aspx?NewMenu”/>
</CustomAction>

<!– 2. Document Library View Toolbar Main Link –>
<CustomAction Id=”UserInterfaceLightUp.DocViewToolbarStatic”
RegistrationType=”List”
RegistrationId=”101″
Rights=”ManagePermissions”
Location=”ViewToolbar”
Sequence=”1001″
Title=”MY STATIC VIEW TOOLBAR ITEM”>
<UrlAction Url=”/_layouts/CustomHello.aspx?ViewToolbar”/>
</CustomAction>

<!– 3. Document Library Toolbar View Toolbar Main Control –>
<CustomAction Id=”UserInterfaceLightUp.DocViewToolbarDynamic”
RegistrationType=”List”
RegistrationId=”101″
Rights=”ManagePermissions”
Location=”ViewToolbar”
Sequence=”1000″
ControlSrc=”~/_controltemplates/CustomHello.ascx“>
</CustomAction>

To define a custom action for a particular menu, you must identify the menu by setting the location to the appropriate Windows SharePoint Services namespace, and by using the ID that Windows SharePoint Services uses to identify the specific location.

For example, to add a custom action to the Site Settings page, set the Location attribute of the CustomAction element to Microsoft.SharePoint.SiteSettings.and specify a particular area within the page through the GroupId attribute.

CustomHello.aspx

<%@ Page Language=”C#” Inherits=”System.Web.UI.Page”%>
<%
string clientQuery = Page.Request.QueryString[“ListId”];

if (clientQuery == “NewMenu”)
{
Response.Write(“You came from the new document menu.”);
}
else if (clientQuery == “ViewToolbar”)
{
Response.Write(“You came from the view toolbar menu.”);
}
else if (clientQuery == “ActionsMenu”)
{
Response.Write(“You came from the actions menu.”);
}
else if (clientQuery == “SettingsMenu”)
{
Response.Write(“You came from the settings menu.”);
}

CustomHello.ascx

<%@ Control Language=”C#” compilationMode=”Always” %>
<%@ Register    Tagprefix=”SharePoint”
Namespace=”Microsoft.SharePoint.WebControls”
Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Import Namespace=”Microsoft.SharePoint” %>

<div>
Hello World!
</div>

Advertisements

One Response to “How to Add Actions to the User Interface?”

  1. Stefano said

    THANKS !!!! I’ve spent all morning trying to add a custom action to the toolbar ! Yours is the only article really useful that I’ve found !

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

 
%d bloggers like this: