Saturday, November 22, 2008

Custom Actions in SharePoint 2007

WSS 3.0 and MOSS 2007 now have a supported extensibility mechanism allowing developers to easily add links to existing menus or Site Settings.

 

Custom Actions can be used to add new custom functionality to many places in WSS and MOSS. Depending on where the custom action is located determines the user interface of the custom action. For example if you create a custom action for the Site Actions menu the result is a menu item anchored in the control. If you create a Custom Action for the Site Settings page you will see a link.  Creating a custom action for a list's display form toolbar results in a toolbar button. As you can see just from this small list a Custom Action provides a lot of extensibility in WSS and MOSS.

Each custom action exists in a specific location, and depending on that location, can be a part of a group of actions. You can find the Default Custom Action Locations and IDs in Microsoft site.

With a custom action feature, you can:

  • Add a new Custom Action Group which can be used to group custom actions in a specific options screen;
  • Add a new Custom Action which can be a new option in a settings screen, a new menu item, or a new toolbar button;
  • Hide an existing Custom Action whether that action is the result of custom action feature or it belongs to SharePoint's out-of-the-box features.

 

How to Create a Custom Action Feature

  1. Create a new Project in VS 2008.
  2. Within the project create the following folder structure image
  3. Within the MyCustomActions folder, Add a new item and select XML file. Name it as CustomActions.xml
  4. Add the following text and make the changes accordingly.

    <?xml version="1.0" encoding="utf-8" ?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <!-- Custom Action Group -->
    <CustomActionGroup
    Id="MyActionGroup"
    Description="This group contains all my custom actions."
    Title="My Action Group"
    Location="Microsoft.SharePoint.SiteSettings"
    Sequence="30" />

    <!-- Custom Action in Custom Action Group -->
    <CustomAction
    Id="MyCustomAction"
    Description="This link is a custom action."
    Title="My Custom Action"
    GroupId="MyActionGroup"
    Location="Microsoft.SharePoint.SiteSettings"
    Rights="ManageWeb"
    RequireSiteAdministrator="FALSE"
    Sequence="20">
    <UrlAction Url="~sitecollection/_layouts/MyCustomPage1.aspx" />
    </CustomAction>

    <!-- Custom Action in Site Actions Menu -->
    <CustomAction
    Id="MyNewCustomAction"
    Description="This menu item is a new custom action."
    Title="My New Custom Action"
    GroupId="SiteActions"
    Location="Microsoft.SharePoint.StandardMenu"
    ImageUrl="/_layouts/MyActionIcon.jpg"
    Sequence="10">
    <UrlAction Url="~sitecollection/_layouts/MyCustomPage2.aspx" />
    </CustomAction>

    <!-- Hide Custom Action -->
    <HideCustomAction
    Id="HideDeleteWeb"
    GroupId="SiteAdministration"
    Location="Microsoft.SharePoint.SiteSettings"
    HideActionId="DeleteWeb" />
    </Elements>

     




  5. Within the MyCustomActions folder, Add a new item and select XML file. Name it as feature.xml


  6. Add the following text and make the changes accordingly.

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

    <Feature  Id="Paste your NEW GUID Here"


              Title="My Custom Actions"


              Description="My Custom Actions"


              Version="12.0.0.0"


              Scope="Site"


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


      <ElementManifests>


        <ElementManifest Location="CustomActions.xml" /> 
      </ElementManifests>


    </Feature>




  7. Build the project using WSPBuilder and deploy the WSP.



Custom Actions really provide us with a great mechanism to place our needed extensions into the menus of WSS and SPS. This post about Custom Actions is a very simple start to what you can do. If you want to know more about Features, check this nice article SharePoint 2007 Deployment: Overview.

Monday, November 10, 2008

Error - You need to be a site collection administrator to set this property

Today I restore a site collection from different server to my VM and when I try to update the site Collection Administrators info on the site I received “you need to be a site collection administrator to set this property”. And also I don’t see the Site Settings and others which you normally see under site Action menu.

 

After a quick google, I found that Site Collection was locked and I need to unlock it. To unlock site collection, Go to central Admin –> Application Management. Click on “Site collection quotas and locks” under “SharePoint site Management”, then select “Not Locked” option.

 

Hope this post helped someone.