SharePoint 2010: Introducing the Client Object Model

SharePoint 2010

 

Today

If you want to access SharePoint Server 2007 Data today, you have two ways of doing it (based on your needs):

  1. Writing a Server Application
    • This application resides in server
  2. Writing a Client Application
    • This client application can run from any other server or a desktop

How are we building these Server and Client applications today?

Server Application

SharePoint Server Application

We interact with the Server Object Model, which are nothing but SharePoint APIs and build applications.

For example:

List<Announcement> announcements = new List<Announcement>();
SPSite site = SPContext.GetContext(HttpContext.Current).Site;
using (SPWeb curWeb = site.OpenWeb())
{
      SPList lstAnnouncements = curWeb.Lists[new Guid(LibraryName)];
 
      //rest of the code
}

Client Application

SharePoint Client Application

We use the SharePoint Web Services which then interacts with the SharePoint API. Usually, developers either build their own set of web services which exposes only certain methods/functions they want to expose to the application or consume the default out of the box SharePoint web services. This becomes difficult if you are going write rich client applications such as Silverlight, or Javascript applications and most of the time accessing SharePoint data via web services is complicated. That is why, I am not going to show you an example code!

The Future of SharePoint Client Applications

SharePoint 2010 introduces the new Client Object Model. From the sneak peak videos:

“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.”

So, how things are going to change?

Shareoint Client Application

One API to rule them all – Yep, whether its WPF or Windows Forms or Silverlight or Javascript – your code uses Client Object Model to interact with the SharePoint site to access the data. Now, there is something common that everybody can use instead of creating their own wrapper services to access SharePoint data!

Any code sample?

The only source of information available for now is the Developer Sneak Peak Video.

In the video, a Silverlight application is built using the Client Object Model.

The assemblies added to the project are:

Client Object Model

  • Microsoft.SharePoint.Client.Silverlight.dll
  • Microsoft.SharePoint.Client.Silverlight.Runtime.dll

And also there is a using statement added in the code behind:

Client Object Model

using Microsoft.SharePoint.Client;

And the code showcasing this new Client Object Model:

Client Object Model Code

You can explore the Microsoft.SharePoint.Client namespace in the SharePoint 2010 Technical Preview Documentation

Microsoft.SharePoint.Client namespace

Lets hope this Client Object Model simplifies accessing SharePoint data from client applications :)


Comments

pingback

Pingback from cosier.wordpress.com

SharePoint 2010 Client Object Model «  Matthew Cosier’s Blog

trackback

SharePoint Development Weekly Roundup (25Aug)

TOP THIS WEEK  How I Benefit from Native Boot From VHD Reza Alirezaei's Blog

trackback

SharePoint 2007 resources - August 2009: Administration, WCMS and virtualization (Hyper-V)

SharePoint 2007 resources - August 2009: Administration, WCMS and virtualization (Hyper-V)

pingback

Pingback from changeq.wordpress.com

WPF Patterns, Frameworks and Practices  «  ChangeQ Blog

pingback

Pingback from ashwinbhagwat.wordpress.com

SharePoint 2010 – Client Object Model « Ashwin Bhagwat's Blog

Dec 13 Model

Model

Nice intro to the client object model.

Mar 11 Praveen

Praveen

Nice post,
I have written a detailed post on complete details of CLient Object Model in SharePoint 2010 here.

praveenbattula.blogspot.com/.../...ails-about.html

Mar 17 Javier Lagos

Javier Lagos

Hi Chaks !

I am still truggling with more advanced data types from Silverlight to Sharepoint 2010 and I am wondering if you were able to create programatically items in a list that contain a Managed Metadata column ?
I cannot do it   :-(   I have sent   "termString|termGUID" as a string but it does not work and I am stuck on this.
Also: do you know how could I get programmatically all the available terms in a particular Term Store ?
Since the terms are stored somewhere else than traditional lists like Tasks, Contacts, etc.  I really do not know how  Frown((

Any help is greatly appreciated !!

Thanks and best regards,

Javier L.
Montreal, Canada

May 15 Beezler

Beezler

Hi Javier,

Here is a sample to get all terms in a store. Did you figure out how to set items in a list "termString|termGuid" is what I tried (and failed) to do as well.

Hope this helps
Beezler


namespace sharepoint.sample
{
    [DataContract]
    public class LookupTag
    {
        [DataMember(IsRequired = true)]
        public Guid TagId;
        [DataMember(IsRequired = true)]
        public string Name;
        [DataMember(IsRequired = false)]
        public string Path;
        [DataMember(IsRequired = false)]
        public string Description;

        public override string ToString()
        {
            return Name;
        }
    }

    internal class Lookup
    {
        public List<LookupTag> GetTagList(string uri, string groupName, string termsetName)
        {
            List<LookupTag> results = new List<LookupTag>();

            using (SPSite site = new SPSite(uri))
            {
                TaxonomySession session = new TaxonomySession(site);

                TermStore store = session.TermStores["Managed Metadata Service"];

                var g = (from gp in store.Groups
                         where string.Compare(gp.Name, groupName, true) == 0
                         select gp).Single();

                TermCollection terms = (from s in g.TermSets
                                        where string.Compare(s.Name, termsetName, true) == 0
                                        select s.Terms).SingleOrDefault();

                ProcessTermSet(results, terms, string.Empty);
            }

            return results;
        }

        private void ProcessTermSet(List<LookupTag> results, TermCollection terms, string path)
        {
            foreach (Term term in terms)
            {
                LookupTag tag = new LookupTag() { TagId = term.Id, Path = path + term.Name, Name = term.Name, Description = term.GetDescription() };
                results.Add(tag);

                if (term.TermsCount > 0)
                {
                    ProcessTermSet(results, term.Terms, tag.Path + "\\");
                }
            }
        }
    }
}

May 15 Beezler

Beezler

Hey Javier,

I've followed your progression through many forums. I have been trying to solve the same problem. I think I have figured it out.

I created a Managed Metadata column on my Document Library. I named it DocTags and assigned a TermSet to the column. Allows multiple was checked. I could then iterate over the ListItem field called "DocTags" as an object[]. Each object was a string in the form of "termName|termGUID" as you already know. I have since found a field called "DocTagsTaxHTField0" which is of type string. The content is formatted in "termName1|termGUID1;termName2|termGUID2". If I set that field, then Update(), ExecuteQuery() as you described. Then I can see my terms in "DocTag", remember this is the column I created originally. As important they are correctly set in SharePoint.

BTW, I am using the .Net Client Object Model, but it should be very much the same.

Hope this helps, I spent a day trying to figure it out, hopefully I save someone, somewhere some pain.

Enjoy,
Beezler

Aug 17 Brian

Brian

Can you show and example of your code?

Thanks
Brian

Aug 06 bharath

bharath

Hi,

I am looking for a way to get properties of each file version for each in COM.
In SharePoint Object model, we have a SPFileVersion class in that i used SPFileVersion.properties to get all the properties for each file version. But
in COM FileVersion class there is no method to get the properties for each file version. Is there a way to get file version properties in COM ?

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading





Creative Commons License
Chaks' Corner Blog by Chakkaradeep Chandran is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Based on a work at www.chakkaradeep.com.
Permissions beyond the scope of this license may be available at http://www.chakkaradeep.com.