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

Azure OpenAI Chat and DALL-E in C# and Python

Azure OpenAI Chat in C#: // Install the .NET library via NuGet: dotnet add package Azure.AI.OpenAI --version 1.0.0-beta.5   using System; u...

Popular posts