Skip to main content

Simple SharePoint 2010 Ribbon example

As we all know SharePoint 2010 came with the new ribbon interface. I have not had much time exploring how to add elements to the ribbon, so I decided to have a go at it.


I decided to use a blank site and try to add a ribbon to the main web part page. With god help from the Professional SharePoint 2010 Development book, here is how i did it.


I started by creating two projects in my solution, one to deploy the images and one to deploy the ribbon feature. The reason for this is that I like to use the sandbox solutions as much as possible. As the images are going into the _layouts\images catalog and therefor needs to be a Farm solution and the ribbon with only one feature can be a sandbox solution.


The way the Ribbons are organized are by a path. In my example the path is “Ribbon.WebPartPage.Edit.Controls._children” , here I'm saying that I want my ribbon to be on WebPart pages under the edits controls, _children means that I want it as new child not override an existing one. I found this path in the \TEMPLATE\GLOBAL\XML\CMDUI.XML where all the out of the box ribbons are described.


So with the knowledge of the path of the ribbon controls I was able to add the new icon to the webpart page. Here is the elements.xml used to do that.



<elements xmlns="http://schemas.microsoft.com/sharepoint/">
<customaction id="MyRibbonTab" location="CommandUI.Ribbon" title="My Ribbon icon">
<commanduiextension>
<commanduidefinitions>
<commanduidefinition location="Ribbon.WebPartPage.Edit.Controls._children">
<button id="Ribbon.WebPartPage.Edit.Controls.RibbonTest" alt="Test Button" command="Test_Button" labeltext="Click Me!!" image16by16="/_layouts/images/XMLRibbonEksample/Smile16x16.gif" image32by32="/_layouts/images/XMLRibbonEksample/Smile32x32.gif" templatealias="o1">
</button></commanduidefinition>
</commanduidefinitions>
<commanduihandlers>
<commanduihandler command="Test_Button" commandaction="javascript:alert('Hello world!!');">
</commanduihandler>
</commanduihandlers>
</commanduiextension>
</customaction>

And a screen shot of the icon.

Comments

Popular posts from this blog

CSOM System Update that does not update minor version number

I was in a scenario where I had to do a add some data to a document list in a web job. My issue was that I could not find any system update method in the CSOM API. After searching it i found a blog post showing that one could just override the system fields, like Modified and Editor(Modified My). That seemed to work but that did not stop it form updating the version number of the document. This example will only work for minor unpublished version. I have not found a way to do this without a published version. There it will get a new minor version. The solution combines the use of adding Editor, and Modified with the use of the ValidateUpdateListItem metod. I found that one can set the item values on the item and just set one value in the form value list, then it will update all the fields. If one then set the "bNewDocumentUpdate" it will not update the version number if it is a minor version. So what i do is just get the values from the item before an update, then sets...

No more features

An aria is over, I'm quit happy to see the new methods to use with provision of SharePoint solutions. https://channel9.msdn.com/blogs/OfficeDevPnP/PnP-Web-Cast-Feature-framework-vs-Remote-Provisioning

Log4Net MVC.net and what web config to use

I'm new to using log4net ( remember using it a long time ago .net 2 area) so I did a rookie mistake. I trying to set it up using resources i found on the net (mainly http://www.codeproject.com/Articles/140911/log-net-Tutorial). But it did not log anything, and I did not get any errors in the Visual Studio  output. After some time and testing I found that because I had put the configuration part under the Views folder, I have to point to that config file. The reason was that I got an error stating that I can only have one configuration section in the web.config, if I added a configuration section in the root web.config. So then I tried to set the assembly section in the AsseblyInfo file to point to the web.config in the Views folder. Then it worked. [assembly: log4net.Config.XmlConfigurator(ConfigFile = "View\\Web.Config", Watch=true)]