Created
April 9, 2014 17:33
-
-
Save madhur/10295125 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.SharePoint.Client; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace SPUpdateField | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
ClientContext ctx = new ClientContext("https://teams.aexp.com/sites/excel"); | |
List list = ctx.Web.Lists.GetByTitle("Idea"); | |
ListItemCollection items = list.GetItems(CamlQuery.CreateAllItemsQuery()); | |
ctx.Load(items); // loading all the fields | |
ctx.ExecuteQuery(); | |
foreach (var item in items) | |
{ | |
ctx.Load(item); | |
ctx.ExecuteQuery(); | |
// important thing is, that here you must have the right type | |
// i.e. item["Modified"] is DateTime | |
FieldUserValue val = item["Old_Created_By_Person"] as FieldUserValue; | |
if (val != null) | |
{ | |
item["Author"] = val; | |
// do whatever changes you want | |
item.Update(); // important, rembeber changes | |
ctx.ExecuteQuery(); | |
Console.WriteLine("Updating " + item.Id); | |
} | |
} | |
Console.WriteLine("Done"); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment