Friday, April 2, 2010

Using Custom Actions in SharePoint 2010

Title: Using Custom Actions in SharePoint 2010

Details: Using Custom Actions in SharePoint 2010 is not different as you create them in either WSS3.0 / MOSS 2007. In this post I will run through the sample of creating your own Custom Group and then a Custom Action link under it. Now before we proceed, I created a very nice pic of mine and sized it to 48x48 and copied it to the 14 hive / Template / Images folder ( named as SiteSettings_SriniSistla_48x48.jpg in this case ). Alright, now lets proceed for few steps.
Step # 1 Create a folder ( MyCustomActions in my example ) with a proper name of your choice
Step # 2 Add a new file to the folder and name it as Feature.xml
Step # 3 Add the content as shown in below code and customize it to your needs. Well, notice that this feature is Scoped to Site and you can create a feature for any scope based on where you want to have the Custom Action.
<?xml version="1.0" encoding="utf-8"?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
 ActivateOnDefault="FALSE" 
 AlwaysForceInstall="FALSE" 
 AutoActivateInCentralAdmin="FALSE" 
 Description="Will Create a Section and Link to my Blog" 
 Hidden="FALSE" Id="90C924A7-32F7-4C19-BD4C-AF49EF0563A9" 
 Scope="Site" Title="My Custom Actions">
 <ElementManifests>
 <ElementManifest Location="MyCustomActions.xml" />
 </ElementManifests>
</Feature>
Step # 4 Create another file in the same folder ( myCustomActions.xml in my example ) and name it as Elements.xml or of your own choice
Step # 5 Add the content as shown in below code and customize it to your needs.
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomActionGroup Description="Srini Sistla Exclusive Custom Group" Id="SriniSistla" Url="/_layouts/images/SiteSettings_SriniSistla_48x48.jpg" 
Location="Microsoft.SharePoint.SiteSettings" Sequence="111" Title="Srini Sistla Blog Details">
  </CustomActionGroup>
  <CustomAction GroupId="SriniSistla" Id="UserInterfaceCustomActions.SiteSettings"  Location="Microsoft.SharePoint.SiteSettings" Sequence="106" Title="Blog  Link">
     <UrlAction Url="http://codename-srini.blogspot.com" />
  </CustomAction>
</Elements>
Step # 6 Now, notice that I have a CustomActionGroup created first ( with Id = SriniSistla ) that I will use it in my CustomAction Section. You can create of your own choice in this case.
Step # 7 Once you have everything in place, copy this folder to 14 hive > Template > Features.
Step # 8 I am happy for now in still using STSADM commands and I will go ahead and use the Install Feature Command here.
stsadm -o installfeature -filename MyCustomFeature\Feature.xml
Step # 9 You can as well activate the feature using Stsadm itself, however you can as well go and activate your feature from the Site collection features link under Site Actions > Site Settings > Site Collection Administration as shown below.








Step # 10 Once you activate the feature, you will find the Custom Actions group and the Custom Actions Link on your site actions > site settings page as shown below.
















So far so good. Notice the GroupId="SriniSistla" in my example. If you want to add to an already existing out of the box groups use below GroupId's.

First, to Add your Custom Actions under Site Actions > Site Settings Page set the Location="Microsoft.SharePoint.SiteSettings" and
GroupID="Customization" to add under 'Look and Feel Section'
GroupID="Galleries" to add under Galleries'
GroupID="SiteAdministration" to add under 'Site Administration'
GroupID="SiteCollectionAdmin" to add under 'Site Collection Administration'
GroupID="UsersAndPermissions" to add under 'Users and Permissions'

for entire Custom Actions list, refer to the msdn site here.
have fun.

6 comments:

Anonymous said...

I like the idea of the lab, but it needs to work! You have to fix both your feature and element xml file for it to work.

Anonymous said...

Nice lab but it doesn't Work!!! You have to fix the case in both of the files for this to work not a good post!

Jonathan said...

Just to note, the code as it exists in the article is non-functional due to being in all lower case. Sharepoint is case sensitive on the XML tags, and has to have the case exactly correct.

Srini Sistla said...

Hello every one... thanks for your valuable comments and observations.

Ruwan Fernando said...

Note that if you are trying to do this on SharePoint online the custom action group will not be deployed because custom action groups cannot be deployed through a sandbox solution.

Anonymous said...

Nice post, thanks.

Another sample to add a custom action to a ribbon bar you can find below. The sample adds a "Export to PDF" button to export SharePoint list data into a PDF document using a templating system:
http://www.parago.de/2011/04/how-to-export-sharepoint-task-list-data-to-pdf-using-a-templating-system/