Provisioning in SharePoint has always been not the simplest part, especially if it concerns the Content Type provision.
It is known that in SharePoint 2010, you can declare content types in a feature or you can create them programmatically. Programmatically created content types are more flexible and provide more granular control over how and when updates to the content type are made during upgrades. In contrast, you cannot change the declarative definition of a content type that was created by using Collaborative Application Markup Language (CAML) after the content type is activated—instead, you must update the content type programmatically.
Given the Pros and Cons, it is up to you to decide which way is better suits your needs.
How to create a field based on the specified schema
There is one method that allows to create a field based on the specified schema, see AddFieldAsXml method for details . It means that you could declare a field once (CAML), but to provision it either via feature activation or programmatically. As for me, I find this technique very useful for curtain cases. But what about content types?
For content type there is no such capability that allows to create a content type based on the specified schema. And the goal of this post is to demonstrate how it could be achieved.
How to create a content type based on the specified schema
Listing 1. AddContentTypeAsXml method implementation for creating a content type based on the specified schema
Listing 2. AddContentTypeAsXml method implementation for creating a content type based on the specified schema via Managed Client Object Model
The following list summarizes the limitations for Client OM approach:
- Not the all content type attributes could be specified via Client OM
- In particular it is not supported to specify Content Type Id, only parent Content Type could be specified
SharePoint 2013 introduces functionality to integrate location information and maps in SharePoint lists and location-based web and mobile apps for SharePoint with the following capabilities:
- new field type named Geolocation that enables you to annotate SharePoint lists with location information. The built-in Geolocation field can render only with Bing Maps. However, you can create a custom field by using the Geolocation field as a parent field type, for example see my blog post about using Google Maps as map service.
- Map View that displays a map (with data obtained from the Bing Maps service), using longitude and latitude entries from the Geolocation field type
Client-side rendering for Map List View in SharePoint 2013
Map List View in SharePoint 2010
But what about SharePoint 2010? Let’s discuss one approach related with customizing List View for XSLTListViewWebPart (XLV) . So, in proposed solution geographical locations are stored in Custom List and custom View is used to render data on Map using Google Maps service For example, list items
will be represented in Map View as shown below
Implementation of Map List View in SharePoint 2010
As was noted earlier for storing geographical location on a map and visualizing it in Map View we will define Custom List named GeoMap List.
GeoMap Content Type
For storing geographical locations we define the following Content Type
GeoMap List is based on Generic List with GeoMap Content Type and with custom View
XSLT stylesheet for Map List View
GeoMap rendering control
- How to: Customize the Rendering of a Field on a List View in SharePoint 2010 on MSDN
- How to: Customize a list view in apps for SharePoint using client-side rendering on MSDN
The creation of non standard presentations for Lists/Libraries is a fairly common scenario and using the XSLT List View Web Part (XLV) possibilities that can be achieved pretty easily.
Let’s take a look how to render list of question and answers using Accordion Menu in SharePoint. Actually the idea for this post appeared after posting of corresponding question on StackOverflow.
So, let’s discuss how it could be accomplished using XLV. For Accordion we will utilize jQuery UI library.
FAQ Custom List
First of all, let us define where the questions and answers (FAQ) we’ll be stored. For this we will use Custom List with Content Type.
After creating Custom List we add new View for displaying Accordion for FAQ items
XSLT style sheet for rendering Accordion View
XSLT style sheet for FAQ List is intended for the following purposes:
- loading jQuery Core and UI Libraries
- rendering list items using layout as specified for Accordion menu
- initializing and rendering Accordion for List items
Using jQuery UI Accordion
FAQ List Accordion View rendered in XLV is shown below on picture
In previous post we have discussed approach on how to embed video into SharePoint from YouTube. Custom List Video Links were used for storing embedded video properties and Computed Field for rendering Video player.
This time we will extend our solution with the following capabilities:
- Support for different video providers listed in oEmbed
- Preview view for displaying video arranged in list
- Alternative mode for posting the embed code for video into SharePoint
Support for different video providers
In addition to embed code using iframe, another options also available now. Some providers listed in oEmbed specification use object element for embedding code.
Table 1. Support for Video Providers listed in oEmbed specification
Alternative mode for posting embedded code
Additionally to existing mode for embedding video code, the approach described below allows to paste the embed code as it was generated by Provider. Let’s take a look at the common usage scenario:
- Generate and copy the embed code on the Provider website
- Select Embed Code from New Item for Video Links List
- In New Form for Video Links List paste the embed code and fill in comments if needed as shown below
For displaying video player the same (see previous post for details) Computed Field EmbeddedVideoOnForm field is used
Preview view for displaying video
In addition to default view (video player items with details), Preview view is intended to display items arranged by columns as shown below
To paste the embed code we define Embed Code Content Type
where field EmbedCode for storing the embed code is used
As was noted earlier, for displaying video player the same (see previous post for details) Computed Field EmbeddedVideoOnForm field is used, below is presented complete XSLT style sheet for rendering of a field on a List View
The solution described here allows to embed video hosted on YouTube into SharePoint. The same approach may be applied for embedding video from another video hosting sites, for example from Vimeo.
The main idea here to store embedded video properties and not the embedded code itself.
For storing embedded video properties we will use Custom List, see implementation section for description. Page for Video Links list (default view with embedded player) is shown below
In order to embed a video into SharePoint:
- On YouTube site click the Share button located under the video.
- Click the Embed button.
- Copy at least src attribute value provided in the expanded box (see table 1 for supported attributes).
- Create new Video Link item and paste attribute values for embedded code into Video Links item. Save it.
Table 1. Mapping between embedded code iframe attributes and Video Link item
||Video Links field name
Video Links implementation
As was mentioned earlier only properties for embedded video code are stored and not the embedded code itself. For storing embedded video code properties is used Custom List that extends OOB Links List (TemplateType = 103)
For embedded video properties we create Video Link Content Type that inherits from Link CT (0x0105)
where we define the following fields
Pay attention, for rendering YouTube player Computed Field EmbeddedVideoOnForm is intended.
For rendering of a field on a List View the following XSLT style sheet is used
And finally, we create List Definition Video Links from Content Type Video Link. List schema and Template files for Video Links including whole project may be found on GitHub.
- Video Links project on GitHub
- How to embed Vimeo player see here
- How to embed YouTube player see here
- How to customize the rendering of a field in List View see here
Posted in SharePoint 2010
- Tagged Computed Field, Content Type, Custom List, Links List, List Definition, List Schema, List Template, SharePoint, SharePoint 2010, Vimeo, XSLT, YouTube