Saturday, October 20, 2012

Update Shared Document Custom Fields Using Client Object Model in SharePoint 2010


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;

namespace MYItemUpdate
{
    class Program
    {
        static void Main(string[] args)
        {
            getfiles();
        }

        private static void getfiles()
        {
            ClientContext clientContext = new ClientContext("http://server-sp:6677/sites/HRDocuments/");
            clientContext.Credentials = new System.Net.NetworkCredential("username1""pass@1234","myDomineName1");
            List list = clientContext.Web.Lists.GetByTitle("Shared Documents");
            CamlQuery camlQuery = new CamlQuery();
            camlQuery.ViewXml = @"<View Scope='Recursive'></View>";

            camlQuery.FolderServerRelativeUrl = "/sites/HRDocuments/Shared Documents/Pay Slips";

            SP.ListItemCollection listItems = list.GetItems(camlQuery);
            clientContext.Load(listItems);
            clientContext.ExecuteQuery();

            SP.ListItem itemOfInterest = listItems[0];
            Console.WriteLine(itemOfInterest["Employee_x0020_ID"].ToString());
            itemOfInterest["Employee_x0020_ID"] = "66";
            itemOfInterest.Update();
            clientContext.ExecuteQuery();

            listItems = list.GetItems(camlQuery);
            clientContext.ExecuteQuery();

        }
    }
}

No comments:

Post a Comment

Featured Post

Create SharePoint Folder Structure in Destination (Only If Not Exists)

Why This Script Is Safe You can run it multiple times It will not create duplicate folders It will only create missing folders S...

Popular posts