LH SharePoint SIG

advertisement
LH SharePoint SIG - Custom
Actions
Custom Actions
A custom action represents a Server ribbon, menu, or link customization that
a user can see. Custom actions can be bound to list type, content type, file
type, or programmatic identifier (ProgID).
Possible scopes:
• Farm: Yes
• Web Application: Yes
• Site Collection: Yes
• Web Site: Yes
We will create a custom action associated with the ribbon for a particular
content type at Site scope
Getting Started
• Our action will allow us to copy Wiki Pages from a Wiki Page Library to
another named “Squirrel Wiki Pages”
•
•
•
•
•
•
Create new Visual Studio 2010 Empty SharePoint project
Add New Item – Empty Element – Squirrel Action
Rename Feature to Squirrel Action
Add CustomAction element to elements.xml
Add Layouts folder for image and add image
Deploy and Test
This is a dumb Custom Action since it does not do anything. Lets put some
meat on the bone…
CustomAction Element
• How did I determine RegistrationType and RegistrationId?
– Go To Site Settings/ Site Content Types
– Hover over “Wiki Page” and look at ctype param in the status bar
• How did I determine Locations?
– Default Custom Action Locations and IDs
– 14 Hive/TEMPLATE/GLOBAL/XML/CMDUI.XML
• How did I determine TemplateAlias?
– 14 Hive/TEMPLATE/GLOBAL/XML/CMDUI.XML
Smart Custom Action
We will now implement some functionality by specifying some ECMAScript
(javascript) in place of the “Hello Word” stuff that will utilize the
SharePoint Foundation 2010 Managed Client Object Model
The Client Object Model is a set of javascript namespaces and classes that
closely mirror the .NET SharePoint Foundation classes and can be used clientside to interact with the SharePoint Object Model.
This is done by packaging up a series of “commands” and sending them to the
server. The communication is asynchronous and you must specify a
completion routine to capture the “results”.
The tricky part is knowing when to make the asynchronous calls.
Smarter Custom Action
Specifying all of the javascript inline is cumbersome and frankly unappealing
We can specify a javascript file and get it on the page by a “ScriptLink” custom action
One benefit is that it can be modified without reinstalling the feature.
Another is that we can get intellisense for the Client Object Model in Visual Studio. Where
would we be with intellisense and Google!
Intellisense provided by lines
/// <reference path="/_layouts/MicrosoftAjax.js"/>
/// <reference path="/_layouts/SP.debug.js"/>
At top of squirrel.js
A third benefit is that we can debug the script
Smarter Action Steps
• Add Layouts folder and javascript file to folder
• Replace CustomAction element
• Add ScriptSrc Custom Action
Action Handling by Delegate
• The following technique allows handling the command “Server Side”
• We will create a class inherited from WebControl and use it to handle the
command
• The control will be added to the AdditionalPageHead Delegate control
• The CommandUIHandler will execute a postback that the control will
handle
• Replace the Custom Action element
• Add the SquirrelControl class
• Add reference to Microsoft.SharePoint, System.Web and
System.WebExtensions
• Add a Safe Controls entry
Useful References
Customizing and Extending the SharePoint 2010 Server Ribbon
Server Ribbon XML
Using the SharePoint Foundation 2010 Managed Client Object Model
SPListTemplateType Enumeration
Download