Search code examples
c#sharepointsharepoint-2010sharepoint-2007

Does SharePoint 2007 has any Client SDK available?


We have a SharePoint server 2007 and we are trying to make few entries into the SharePoint using the c#.net code. I came to know that we can use the SharePoint Client SDK components. But no where I found the SDK for 2007 version of SharePoint .

Is it possible to use the SharePoint 2013 Client SDK components to access the SharePoint 2007 site and do all the get or update actions ?


Solution

  • Since SharePoint Client Components SDK consists of collection of client-side object model (CSOM) DLLs and CSOM is not supported in SharePoint 2007, there is no release of SharePoint Client SDK for 2007 version.

    But you could utilize SharePoint 2007 Web Services for that purpose, the following example demonstrates how to consume SharePoint Web Services to create a List Item:

    using System;
    using System.Collections.Generic;
    using System.Net;
    using System.Xml;
    
    namespace SharePoint.Client
    {
        public class ListsClient : IDisposable
        {
            public ListsClient(Uri webUri, ICredentials credentials)
            {
                _client = new Lists.Lists();
                _client.Credentials = credentials;
                _client.Url = webUri + "/_vti_bin/Lists.asmx";
            }
    
            public ListsClient(Uri webUri)
            {
                _client = new Lists.Lists();
                _client.Url = webUri + "/_vti_bin/Lists.asmx";
            }
    
    
            /// <summary>
            /// Create a List Item 
            /// </summary>
            /// <param name="listName">List Name</param>
            /// <param name="propertyValues">List Item properties</param>
            /// <returns></returns>
            public XmlNode CreateListItem(string listName,Dictionary<string,string> propertyValues)
            {
                var payload = new XmlDocument();
                var updates = payload.CreateElement("Batch");
                updates.SetAttribute("OnError", "Continue");
                var method = payload.CreateElement("Method");
                method.SetAttribute("ID", "1");
                method.SetAttribute("Cmd", "New");
                foreach (var propertyValue in propertyValues)
                {
                    var field = payload.CreateElement("Field");
                    field.SetAttribute("Name", propertyValue.Key);
                    field.InnerText = propertyValue.Value;
                    method.AppendChild(field);
                }
                updates.AppendChild(method);
                return _client.UpdateListItems(listName, updates);
            }
    
    
    
            public void Dispose()
            {
                _client.Dispose();
                GC.SuppressFinalize(this);
            }
    
    
            protected Lists.Lists _client;  //SharePoint Web Services Lists proxy
    
        }
    }
    

    Usage

    How to create a Task item:

    using (var client = new SPOListsClient(webUrl, userName, password))
    {
        var taskProperties = new Dictionary<string, string>();
        taskProperties["Title"] = "Order approval";
        taskProperties["Priority"] = "(2) Normal";
        var result = client.CreateListItem(listTitle, taskProperties);    
    }
    

    References