Jacob Siggaard’s Blog

February 21, 2011

Client Object Model in SharePoint 2010

Filed under: SharePoint — Tags: , , — Jacob Siggaard @ 8:23 am

Hi

What is the Client Object Model and who are we using it ? I will give an introduction to how this is working in SharePoint 2010.

SharePoint 2010 gives us some new functionality called client object model that enables us to create SharePoint solutions that run remotely from the SharePoint server farm. For example, the client object model enables you to read and manipulate SharePoint data in Windows Forms applications, Windows Presentation Framework application, Silverlight applications, and ASP.NET Web applications.

The picture below shows the “big picture” of how Client Object Model is working.

And the more technical perspective, would look like this:

There are three implementations of Client Object Model, which are WPF or Windows Forms, Silverlight or Javascript – your code uses Client Object Model to interact with the SharePoint site to access the data.

“The Client Object Model (OM) is a new programming interface for SharePoint 2010 where code runs on a user’s client machine against a local object model and interacts with data on the SharePoint Server. Client OM methods can be called from JavaScript, .NET code or Silverlight code and makes building rich client applications for SharePoint easy.”

Very good introduction videos til Client object model, see here, and of course the official MSDN description see here (actually very good).

Then we want to implement the Client OM, here are some useful facts:

When we want to start coding with the Client OM there is a little difference between the server-side object model programming, as the class names are very similar to those used in classes so far (not a clear rule, but in general have been removed the letters “SP” from the names of classes in the client-side API). Some differences are visible in this table.

Server Object Model Client Object Model
SPContext ClientContext
SPWeb Web
SPList List
SPListCollection ListCollection
SPListItem ListItem
SPField Field

Assemblies to use in .NET client object model.
Custom .NET applications will need to add references to two assemblies in order to use the client object model. These two assemblies are found on the SharePoint server: c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI:

  • Microsoft.SharePoint.Client.dll (contains the client object model)
  • Microsoft.SharePoint.Client.Runtime.dll (handles all communication between the client and SharePoint server)

And the using statement will look like this:

  • using Microsoft.SharePoint.Client;

.NET Client OM Code example:

private void btnGetLists_Click(object sender, EventArgs e)
{
lbLists.Items.Clear();

using (SP.ClientContext ctx = new SP.ClientContext("http://sp2010"))
{
var web = ctx.Web;

ctx.Load(web);
ctx.Load(web.Lists);

ctx.ExecuteQuery();

foreach (SP.List list in web.Lists)
{
lbLists.Items.Add(list.Title);
}
}
}


Silverlight client object model:

The Silverlight client object model add the two assembly references found in the c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin folder:

  • Microsoft.SharePoint.Client.Silverlight.dll (contains the client object model)
  • Microsoft.SharePoint.Client.Runtime.Silverlight.dll (handles all communication between the client and SharePoint server)

ECMAScript(javascript) client object model:

The ECMAScript client object model’s ClientContext constructor takes zero parameters because it’s locked to communicating only with the site the page is loaded from. This limitation prohibits cross-site scripting, a universally recognized security exploit.When writing back to SharePoint, the page that contains the ECMAScript should contain an instance of a FormDigest control to create a digest for security validation on the page. For the ECMAScript OM, you need to know some Java library,

  • CUI.js (344 kb)
  • SP.js (381 kb)
  • SP.Core.js (13 kb)
  • SP.Ribbon.js (208 kb)
  • SP. …

We can find them at this path:<Drive>:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS

Detailed description of the things to be aware of when using Client OM, see here.

Best regards
Happy SharePoint 2010 explorer, Jacob

November 9, 2010

BCS in SharePoint 2010

Filed under: SharePoint — Tags: , , — Jacob Siggaard @ 8:16 pm

Hi

All of us that have used SharePoint 2007 also know the BDC and how much it was missing functionality. Now in SharePoint 2010 Microsoft have upgraded the BDC and called it BCS.

The cornerstone of BCS is the concept of an external content type. Data in an organization can live in various back-end systems. An external content type is a content type available in SharePoint 2010 that describes the schema and data access capabilities of an external data source and its behavior within Office and SharePoint 2010. The external content type in BCS is the logical equivalent of what used to be called the Entity in BDC.

External Content Types:

An external content type is a reusable collection of metadata that defines a set of data from one or more external systems, the operations available on that data, and connectivity information related to that data. More details here.

Business Connectivity Services can connect to the following types of external data:

  • SQL Server Databases
  • SAP Applications
  • Web Services – including Windows Communication Foundation (WCF) Web Services
  • SharePoint based web sites
  • Third party applications

Business Connectivity Services Architecture (BCS)

See very detailed examples of using BCS here.

How to configure and use BCS look at this very detailed and useful example here.

Best regards

Happy SharePoint 2010 explorer, Jacob

September 21, 2010

ADO.NET Services(REST) in SharePoint 2010

Filed under: SharePoint — Tags: , , , , — Jacob Siggaard @ 8:31 pm

Hi

REST (Representational State Transfer) is an easy way to query your data in SharePoint 2010, but you can also add data to SharePoint this way. It is used in situations where you would use a web service but don’t want the overhead and tightly-coupled nature of SOAP. REST is a very simple client-server-like request using HTTP to retrieve or send information. Have a closer look here.

In order to use REST/Data Services with SharePoint 2010, ADO.NET Data Services 1.5 must be installed on your server. ADO.NET Data Services 1.5 and SharePoint 2010 allow developers to write applications against SharePoint Lists using the familiar Data Services Client programming model. For more details see here.

A very simple example, on how to use REST, could look like this:

http://sp2010a/teamsite/_vti_bin/listdata.svc/Contacts

Or perhaps just a single contact (in this case, the one with ID = 1)

http://sp2010a/teamsite/_vti_bin/listdata.svc/Contacts(1)

For more detailed examples on how to do queries, data binding, updates and deletes, have a look here.

Best regards

Happy SharePoint 2010 explorer, Jacob

July 13, 2010

Site Pages in SharePoint 2010

Filed under: SharePoint — Tags: , , , — Jacob Siggaard @ 8:01 pm

Hi

In MOSS 2007 we often activated the Publishing feature to be able to store pages in the pages library, but this is not necessary in SharePoint 2010. If we for example take a Team Site as the picture below, we can se that there is a “Site Pages” library and a “Site Assets” library. This is where the pages (Site Pages) and images, video, audio and more (Site Assets) go on a team site. We don’t have to activate the publishing feature to have a place for pages any more. This is so great and something we are really going to enjoy in SharePoint 2010.

For a more detailed description of the “Site Pages” and “Site Assets” have a look at this blog.

Best regards

Happy SharePoint 2010 explorer, Jacob

June 30, 2010

SharePoint 2010 Sandbox Solutions

Filed under: SharePoint — Tags: , , , — Jacob Siggaard @ 6:02 pm

Hi

What is Sandbox Solutions and what are we going to use it for ??

“Sandbox Solutions – In SharePoint 2007, custom code requires the farm administrator to trust the code running on the server. In SharePoint 2010 we are introducing a new SharePoint custom code sandbox with isolation and resource limitations (memory, SQL, CPU) that allows administrators to let others safely add and consume custom solutions without impacting overall farm performance and stability. While it does not cover the full SharePoint object model it addresses key scenarios like custom web parts and event receivers. We will use this and the client side object model described later to support custom SharePoint solutions in SharePoint Online as well.

Debugging - Normally we are used to work with the w3wp.exe process when debugging, which run under the IIS worker process used by SharePoint. Sandboxed solutions run under the process called SPUCWorkerProcess.exe.

“Any solution that is created for Sandbox can be deployed into a special Solutions Gallery in the site-collection called SOLUTIONS GALLERY. And all these solutions that are deployed here can be activated from a menu (ECB menu) on that solutions gallery itself, hover around the item and you will get a ACTIVATE/DEACTIVATE menu. For all this to work properly we have to make sure that the “Microsoft SharePoint Foundation User Code Service” is starting on one or more of the servers in the Farm. You can confirm whether the service is running or not by checking the sandbox resource quota that is available on the top of the same page (Solutions Gallery Page). All of the resource assignment and monitoring for the Sandboxed solution can be controlled from Central Admin app.
Sandboxed Solutions need these 3 things to work:

  • User Code Service (SPUCHostService.exe): this service will decide whether the server on which this service is running will participate in the Sandboxed solutions or not. This service runs on each server on the farm that we are going to allow to work in the sandbox.
  • Sandbox Worker Process (SPUCWorkerProcess.exe): This is the actual process in which the Sandboxed Solutions run.
  • Sandbox Worker Process Proxy (SPUCWorkerProcessProxy.exe): If you have already studied and are aware of the new Service Application architecture then you get this one, this is the proxy which the web-app will use for the proxy group to use the sandbox.”

See more detailed descriptions of each process here.

Overview of the sandbox solutions processes and how they work together.

Sandbox Solutions only support a subset of the normal functionality in SharePoint. I have listed the supported and not supported functionality below.

SandBox Solutions support the following SharePoint item types:

  • List definitions
  • List instances
  • Onet.xml
  • WebTemplate Feature element instead of Webtemp.xml
  • Content Types/Fields
  • Navigation
  • Module/files
  • Feature callouts
  • Web Parts derived from WebPart
  • Event receivers
    • SPItemEventReceiver
    • SPListEventReceiver
    • SPWebEventReceiver
  • Custom Actions
  • Workflows

SandBox Solutions do not support the following:

  • Custom Action groups
  • HideCustomAction element
  • Content Type Binding
  • Web Application-scoped Features
  • Farm-scoped Features
  • CustomPropertyToolPart Class
  • Programmatic workflow
  • Event receivers
    • SPLimitedWebPartManager
  • Timer jobs
  • Visual WebParts
  • SharePoint mapped folders (e.g. “_layouts”, and “images”)

The following .NET namespaces are not supported by sandboxed solutions:

  • ADO.NET
  • System.IO
  • System.Security.Cryptography
  • System.Web.UI.ClientScriptManager

If you need to do things that are not possible with sandbox solutions, you are able to do two things as I see it. The best way to reach out of the sandbox is by using the Business Connectivity Services (BCS) to create an external content type. You can then read and write to the data source from the sandboxed solution. Another, more advanced, way to reach outside the sandbox is to create a class that runs in a full-trust process outside the sandboxed worker process to proxy calls. This proxy class is deployed as a farm solution and is callable from the sandboxed solution.

I’m looking forward to spending some more time on this topic and see if the limitations are going to be that big a problem as I’m worried about at the moment. When searching the web about this topic, I found this great and detailed example on how to use Sandbox Solutions, you can find it here.

Best regards

Happy SharePoint 2010 explorer, Jacob

June 23, 2010

FeatureUpgrading in SharePoint 2010

Filed under: SharePoint — Tags: , , , — Jacob Siggaard @ 9:49 am

Hi

I have started reading about the new version of Sharepoint and I had totally forgot about this new Event receiver on features. The FeatureUpgrading receiver is really a big improvement from the previous version of SharePoint.

In the Feature.xml there is a section for the upgrade senario which is called . This element/section can contain the following subelements:

  • <CustomUpgradeAction> — Allows you to execute custom code when a Feature instance is being upgraded. When an action is specified in an upgrade action sequence, Microsoft SharePoint Foundation calls the FeatureUpgrading method synchronously with other upgrade actions in order of declaration.
  • <VersionRange> — Specifies a version range to which upgrade actions apply.
  • <ApplyElementManifests> — Provisions all non-declarative elements that are referenced in the specified element manifests.
  • <AddContentTypeField> — Adds a new field to a provisioned content type and propagates the change to child lists and content types. For example:

<AddContentTypeField
ContentTypeId="0x010100A6F9CE1AFE2A48f0A3E6CB5BB770B0F7"
FieldId="{B250DCFD-9310-4e2d-85F2-BE2DA37A57D2}"
PushDown="TRUE" />

In most cases, the values of the ContentTypeId and FieldId attributes are specified in the Elements.xml file where the content type and field are defined.

  • <MapFile> — Maps a file that has not been customized to a different path on the front-end Web server. You can use the FromPath  and ToPath attributes to rename a file in a Feature (for example, , but you can also use this element to move a file. In this case, the FromPath and ToPath  attributes specify paths that are relative to the TEMPLATE directory. For example, if a Feature named “MyFeature” has .gif files installed in a “Gifs” directory (such as, %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\FEATURES\MyFeature\Gifs\ball.gif), and in version 2 you want to rename “Gifs” to “Images”, then can be used to move the files.

These subelements can also be found here


An example could be like this CustomUpgradeAction:

Feature.xml:

<UpgradeActions
ReceiverAssembly="ShinyNewFeatureReceiver, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3ef91b1292056a22"
ReceiverClass="ShinyNewFeatureReceiver.MyReceiver">
<VersionRange EndVersion="2.0.0.0">
<CustomUpgradeAction Name="RemoveField">
<Parameters>
ContentType">MemberProfile
FieldName">SSN
</Parameters>
</CustomUpgradeAction>
</VersionRange>
</UpgradeActions>

C# Code:

public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, IDictionary parameters)
{
SPWeb web = thisFeature.Parent as SPWeb;
if(upgradeActionName == "RemoveField")
{
string contentTypeName = parameters["ContentType"];
string fieldName = parameters["FieldName"];
SPContentType contentType = web.RootWeb.ContentTypes[contentTypeName];
contentType.Fields[fieldName].Delete();
contentType.Update(true);
}
}


During my enjoy-time I found this very detailed description of the FeatureUpgrading event receiver in SharePoint 2010, I’m going to love this one. See it here

Best regards

Happy SharePoint 2010 explorer, Jacob

June 21, 2010

Set or Change SharePoint Page Titles (“PlaceHolderPageTitle”)

Filed under: SharePoint — Tags: , , , , — Jacob Siggaard @ 7:15 pm

Hi

Have been working with Page Title on Sharepoint Page Layouts the last couple of days and found this great example. This is the most important stuff I used to make it work.

MasterPage code:

<title ID=onetidTitle><asp:ContentPlaceHolder id="PlaceHolderPageTitle" runat="server"/></title>

Page Layout code:

<asp:Content ContentPlaceholderID="PlaceHolderPageTitle" runat="server">
<SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server"/>
</asp:Content>

I also found another great site during my search on the net. The site makes it very easy to see where the following controls is used on a page:

  • PlaceHolderTitleBreadcrumb
  • PlaceHolderGlobalNavigation
  • PlaceHolderTopNavBar
  • PlaceHolderSearchArea
  • PlaceHolderPageTitleInTitleArea
  • PlaceHolderSiteName
  • PlaceHolderNavSpacer
  • PlaceHolderLeftNavBar
  • PlaceHolderBodyLeftBorder
  • PlaceHolderBodyRightMargin
  • PlaceHolderMain
  • PlaceHolderPageTitle

The site can be found here.

Have a nice summer, best regards Jacob

March 22, 2010

Gradual upgrade in SharePoint 2010

Filed under: SharePoint — Tags: , , — Jacob Siggaard @ 8:44 pm

Hi

I read this blog-post by Joel Oleson today and it really gives a good introduction to a very complex problem in the SharePoint world. A lot of people are thinking about the new SharePoint version that is coming up and how big a job it is to upgrade. It is therefore very important to have the right information to make the right decision.

Microsoft have really tried to make it easier to upgrade to the new version of SharePoint. I like the idea about doing the binary upgrade and then take the visual upgrade on small waves when the departments are ready for it.

At the end of the blog there are some links to more information on how to analyse your current SharePoint environment.

Hope you can use the information, I found the information in the blogs very useful.

Best regards Jacob

September 14, 2009

A closer look into SharePoint 2010

Filed under: SharePoint — Tags: , , — Jacob Siggaard @ 9:31 am

Hi

To have a closer look into the upcoming SharePoint 2010 take a look at the following blog. Screen-dumps and a bit of analyzing. Office Web Applications sounds interesting but I’ll remain skeptical until I have had a deeper look into it.

It seems like that “My Site” will have a new name “My SharePoint”. But why, will the users be able to get understand that. I have met a few users that won’t.

September 9, 2009

SharePoint 2010 new Feature Circle

Filed under: SharePoint — Tags: , , — Jacob Siggaard @ 1:08 pm

Hi all

If you have any interest in the new SharePoint 2010, you really need to have a look at the sneak peek videos here

They have also updated the SharePoint Circle and it looks like this:

sharepointCircle

The 6 areas are:

1. Sites (Share information consistently and securely with all)

2. Communities (Work together in new ways)

3. Content (Content lifecycle, from start to end)

4. Search (Search information from most sources)

5. Insights (Make data more available for more users)

6. Composites (Fast business solutions that is dynamic (let’s see what can be done with this :-) ))

I’m really looking forward to have a deeper look at each area. Se you in Vegas for the conference.

Older Posts »

Theme: Shocking Blue Green. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.