One of the big questions these days is working with SP2010 remotely using web services, client object model or even WCF. Everyone is familiar with SP2007 web services, but the question is whether the same web services work in SP2010. This question came up when I wanted to create a “document set” which is a new feature in SP2010. This a new contenttype that is similar to the folder contenttype in SP2007. It allows much more metadata to be contained and used within a folder. So I thought by just using the Webs.asmx web service and the “CreateContentType” method I could achieve this. Unfortunately not. Below is the code that does not work:
public static void CreateDocumentSetWithWebService()
websservice.Webs ws = new websservice.Webs();
XmlDocument doc = new XmlDocument();
XmlAttribute desc = doc.CreateAttribute("Description");
So I decided to look at the client object model. This is also a new feature in SP2010 and allows remote applications to work with a subset of the SharePoint object model from applications not running on the SharePoint server. The dlls that you need to reference in your project are Microsoft.SharePoint.Client and Microsoft.SharePoint.Client.Runtime. The object model is very easy to use and wraps all the complexity of calling WCF services. Basically you create the objects you want to work with then make the calls using ClientContext.ExecuteQuery method. Very simple.
public static void CreateDocumentSet_ClientOM()
ContentTypeCollection contentTypes = site.ContentTypes;
FieldCollection fields = site.AvailableFields;
ContentTypeCreationInformation ctypeInfo = new ContentTypeCreationInformation();
ContentType newContentType = contentTypes.Add(ctypeInfo);
FieldLinkCreationInformation fieldLinkInfo = new FieldLinkCreationInformation();
It is very easy to remotely integrate your applications with SP2010. SP2010 offers the client object model in three different flavors, .Net, SilverLight and ECMAScript.