CloudShare Blog

What's new in the SharePoint 2013 Client Side Object Model!

So the question here is: What’s new in SharePoint 2013 CSOM? Well, of course the API is there (in the 15 hive) and Microsoft has increased the possibilities of building applications with the CSOM adding new assemblies that allow developers not only to interact with SharePoint sites but also use some of the key SharePoint 2013 services like Search, Managed Metadata or the new Translation service.

As happened in previous versions of SharePoint, SharePoint 2013 is not only a product but also a development platform. Which means you can build new functionalities and capabilities on top of the ones available out of the box. SharePoint 2010 introduced a new extensibility point to build client applications on top of the server object model using a new API: the client side object model (CSOM). The idea behind the CSOM was just to enable developers to work remotely with SharePoint sites without having to use default web services or creating new ones. Microsoft introduced three different programming flavors for creating client applications using the CSOM: .NET, Silverlight and ECMAScript. Even each flavor has its own rules and patterns when using it, behind the scenes all of them do the same: send commands to the server through a WCF (Windows Communication Foundation) service and wait for the server answer.

CSOM Architecture

The foundations of the CSOM architecture in SharePoint 2013 are quite similar to the ones in SharePoint 2010, replacing the “client.svc” WCF service for a new REST API named _api. This REST API is the foundation to use REST to interoperate with SharePoint sites but also to use the CSOM.

image

As you can see, in SharePoint 2013 we have the same three programming flavors for the CSOM, .NET – Silverlight – ECMAScript, which sends commands to the new REST _api and wait for the related answer.

New CSOM assemblies

New assemblies have been provided to developers in order to use some of the SharePoint 2013 services. You can find there in the following locations:

  • .NET flavor (synchronous nature), located at the path [..]\15\ISAPI. It allows you to create desktop or web applications that can interoperate remotely with SharePoint 2013 services and sites.
  • Silverlight flavor (asynchronous nature), located at the path [..]\15\TEMPLATE\LAYOUTS\ClientBin. It allows you to build Silverlight applications deployed and used inside SharePoint sites. Silverlight provided rich user interfaces when building custom solutions on top of SharePoint.
  • ECMAScript (asynchronous nature), located at the path [..]\TEMPLATE\LAYOUTS.

Bellow you can see a screenshot showing some of the assemblies available for the .NET CSOM:

image

CSOM in action: using the new Translation Service Application from a client application

For instance, you can easily use the new Translation Service Application to translate documents in a CSOM application. You have access to either synchronous or asynchronous translation capabilities. You only need to create a ClientContext instance and you are ready to work remotely with the service by using new classes provided by Microsoft. In this case, just create a SyncTranslator instance, configure the translation job and make a call to the Translate() method. Once you call the ExecuteQuery() method you are done and you’ll have your document translated.

        <span class="kwrd">static</span> <span class="kwrd">void</span> TraduccionSincronaClientOM()
        {
            <span class="kwrd">try</span>
            {
                <span class="kwrd">using</span> (MO_Cliente.ClientContext ctx =
                    <span class="kwrd">new</span> MO_Cliente.ClientContext(
                        <span class="str">"http://c4431163311/"</span>))
                {
                    <span class="kwrd">string</span> sEntrada = <span class="str">"http://c4431163311/Entrada/WordAutomation.docx"</span>;
                    <span class="kwrd">string</span> sSalida = <span class="str">"http://c4431163311/Salida/WordAutomationTraducido.docx"</span>;
                    MO_TRCliente.SyncTranslator stJob =
                        <span class="kwrd">new</span> MO_TRCliente.SyncTranslator(
                            ctx, <span class="str">"en"</span>);
                    stJob.OutputSaveBehavior =
                        MO_TRCliente.SaveBehavior.AlwaysOverwrite;
                    MO_Cliente.ClientResult&lt;MO_TRCliente.TranslationItemInfo&gt; cr =
                        stJob.Translate(sEntrada, sSalida);
                    ctx.ExecuteQuery();
                }

            }
            <span class="kwrd">catch</span> (Exception ex)
            {
                Console.WriteLine(
                    <span class="str">"Error: "</span>, ex.Message);
            }
        }

And that’s all about new stuff in CSOM. I recommend you to check it in your SharePoint 2013 CloudShare environment. Happy CloudSharing!

Topics: Dev / Test SharePoint