|
Apr
14
|
Hi, today I will fully explain how to create a “custom action”. For it I will use “Visual studio” and WSPBuilder, you can find it on codeplex.
Our action will appear on the display page of all the items of a custom list. By clicking on it, the user will be redirected to google. A custom action has to be included in a feature, meaning, we will create a standard feature and add code in it to define that we want to create a custom action.
So now let’s get started, you will need to create a new WSPBuilder project (without workflow), when the new project is loaded, choose Add->WSPBuilder->Blank Feature. The system will ask you a name and to choose a scope, in my example the scope choosen is web (for website). If you have done a mistake about the name or the scope, that’ not a problem, you will be able to modify those directly in the XML files.
Now that you’ve created your new feature, you will have in the document explorer an hierarchy like the following picture.
Now you have all your structure done, here is the code to include.
The feature.xml file will contains all information about the feature (title, ID, scope,…), use the intellisense to check what is proposed. The important thing is the link to the manifest, in our case, “elements.xml”.
<?xml version="1.0" encoding="utf-8"?>
<Feature Id="0FE81D03-6AE0-48a0-BBF7-88A1DAA9B04A"
Title="Import UP"
Description="Description for Import User Profiles"
Version="12.0.0.0"
Hidden="FALSE"
Scope="Web"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="elements.xml"/>
</ElementManifests>
</Feature>
The elements.xml file define the content of the feature, in our case a custom action. To find the required fields refer to that MSDN link: CustomAction Element (Custom Action) . What is really interesting is the registrationtype, you can register to some different contents in our case the lists and the registrationID refers to the type of list (100=custom list) we want to add the action in. But you can choose a registration of type content type and give the name of it, so that action will be relevant only for that content type. An important thing is to define the location of the action, where it will appear. The URL define where the users will be redirected when clicking on it, it can be, and probably will be in the real life a custom ASPX page.
Refer to that MSDN link to find all the location and GroupID (in the comments too!): Default Custom Action Locations and IDs
You will see the 2 first columns, location and GroupID, if the GroupID is not empty or not contains N/A, you will have to include it in your custom action element, an example is done at the end of the post.
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="CustomActionGetUerProfiles.CustomAction"
Location="DisplayFormToolbar"
Title="Import Users"
RegistrationType="List"
RegistrationId="100"
Sequence="10"
Description="The description" RequireSiteAdministrator="FALSE">
<UrlAction Url="http://www.google.com"/>
</CustomAction>
</Elements>
Now that you have your two files, your custom action is ready to be deployed, using WSPBuilder, simply choose, “Deploy”. Refresh the page and go to a custom list, if everything goes well when you will click on the view item button, on the next page, above, you will see our “Import user” action. By clicking on it you will be redirected to google.
If in the elements.xml you change the location to Location=”Microsoft.SharePoint.StandardMenu” and include GroupID=”ActionsMenu”, your action will be now on the toolbar of the list in the Action menu and the click will redirect you again to google.
Have a nice day !