Tuesday, June 3, 2008

Custom Action Button on List's Tool Bar, WSS 3.0

Display a Custom Button say “Load Data” on the Toolbar of the Sales List

Solution:
In a Feature say “CustomContextMenu” we declare a Custom Action.

In the elements.xml file at “\CustomContextMenu\elements.xml” you will need to add this snippet.

<CustomAction Id="CustomContextMenu"
RegistrationType="List"
RegistrationId="10031"
Location="ViewToolbar"
Sequence="239"
Title="Load Data" >
<UrlAction Url="~site/PageFilter.aspx?ListId={ListId}&ItemId={ItemId}&SiteURL={SiteUrl}&Action=7"/>
</CustomAction>

Parameters values:

RegistrationType="List"

RegistrationId is the “Type” id found in the elementManifest.xml of the List on which you want to show the button. Here in our case if you open the elementManifest.xml of Sales List.
You will find that “Type” for this list is “10031”

Location="ViewToolbar". We want the Button to appear on the Tool Bar of the List.

In UrlAction mention the url where you want the control to navigate when you press the button.

3 comments:

Innocent Warrior said...

I want to know How to add button to the sharepoint toolbar?

When I implemented your approach, my site went down.

What can be the reason?

Priyanka said...

Hello,

I do not understand the type and RegistrationId thing. I have a created a picture library from UI. The RegistrationType would be list and RegistrationId = ? I do not want to keep it "109" which is the template id for picture libraries, since I want it only for a specific library. You have mentioned something about Type in element.xml, I do not understand that part. Alternatively, can you give some idea?

Parth Patel said...

Hi,
@priyanka: when you do any thing in sharepoint then it has registration id. like custom list has registration id of 100 and your picture library has registration id has 109. so if you are using registration id as 109 then it will applied to all the picture library if you want to do it for some specific library only then you have to create your picture library with custom id (from list definition which is not at all easy).


@innocentwarrior: may be you can use registration id as 100 so it will applied to your custom list the registration id we had used is for custom one. there is nothing that can make your site down :) there might be another issue.




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com