Monday, July 26, 2010

All about the SharePoint Ribbon for developers

Hi all,

I have recently finished working on a new session for developers that I am scheduled to deliver on several user groups and SharePoint Saturdays.

I thought it might be a good idea to post the power point and source code samples online for you to be able to use these samples in your own projects.

This power point and source code includes detailed information on how to customize and manipulate the SharePoint 2010 server ribbon.

The target audience is experienced SharePoint developers.

Note: there is a readme file in the visual studio 2010 project with a script on what's in the source code and how to demo it.

Feel free to comment on the materials here, or if you've attended the session - comment on how did the session go.

I strongly suggest downloading the file rather than viewing it online, you can find it here (to download use the menu at the bottom left):

(Sample source code is embeded in the power point file, so you have to download it to get it)
Thanks, Shai.
=~=~=~=~=~=~=~   Update   ~=~=~=~=~=~=~=
I moved this session to prezi format, source code still inside slide share PPT, but I think the slides part is better in the new format:

Monday, July 5, 2010

SPRibbon.GetCurrent(this.Page).MakeTabAvailable(); not found

If you try to work with contextual tabs, you might want to use server side in order to make these tabs visible.

Please see a link here to a good article about this by Chris O'brien:

But, if you just create a new SharePoint solution these methods will not be available to you:

The reason is, that these 2 new commands are infact a part of Microsoft.Web.CommandUI DLL, which is available outside of the SharePoint DLL, hence when you only have a reference to SharePoint DLL's you will see the SPRibbon object but some functionality inherited from it's base type will be hidden.

So - add a reference to Microsoft.Web.CommandUI and you'll be good to go!

Visual Studio 2010 for SharePoint - need more templates?

If you (like me) wished there were more templates in Visual Studio 2010 for SharePoint, like Ribbon control or other cool features - your prayers have been answered here:

After installing this I was able to add a new component to my SharePoint project named "Server Ribbon"!

Hope to see much more of these in the new future.

(You can also find this useful post on "SharePoint 2010 Extensibility Projects: Server Ribbon" by Paul Stubbs ).

Enable or Disable buttons in SharePoint Ribbon

A few days ago I was doing some reading on the web and I ran across Chris O'Brien post on the ribbon:

(very good post, recommended to everyone if you want to get to know the ribbon better!)

In the first part of this post there is a sample ribbon tab with 4 buttons dependent on one another.

Meaning: clicking one button should enable or disable other buttons on the ribbon (Same tab, different groups).

This was supposed to be easy to achieve using the "EnabledScript" attribute on the CommandUIHandler associated with the buttons needed to be changed.

In my RTM machine, clicking one button did not change the status of the other buttons. After a little research I learned that other examples of enabling a button based on selected list items do work.

I then figured out that were was some update or refresh code running when selecting a list item that was not running during a click on my ribbon button.
This led me to find that in Chris's example, if I select an item after changing the flag - the buttons get enabled as they should!

To keep it short, there is a Javascript method called "RefreshCommandUI" that gets called after certain events in SharePoint (Like selecting an item in a list view) which is responsible to handle all updates of the ribbon.
These updates include:
1. Showing or hiding a contextual tab based on context
2, Enabling or Disabling buttons in the current active tab

Note, that this command does not run on buttons that are not active, but as soon as your tab will become active it will trigger the "EnabledScript" so not to worry!

Anyway, Thanks Chris for the great post, I hope this little fix here will make your ribbonizing experience even more smooth and worth while!

Shai Petel.