Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using(SPSite site = new SPSite("https://yourspsite"))
- {
- using(SPWeb web = site.OpenWeb())
- {
- SPList listA = web.Lists["listA"];
- SPList listB = web.Lists["listB"];
- // Assuming list A users are unique (based on your requirement)
- SPListItemCollection usersOnListA = listA.GetItems();
- SPListItemCollection usersOnListB;
- SPQuery query = new SPQuery();
- query.RowLimit = 1
- foreach(SPListItem userListA in usersOnListA)
- {
- // Get user on list B whose name is equal to user on list A, ordered descending by its date
- query.Query = @"<Where>
- <Eq>
- <FieldRef Name='Employee_x0020_Name' />
- <Value Type='Text'>"+ userListA["Emplloyee_x0020_Name"].ToString() +@"</Value>
- </Eq>
- </Where>
- <OrderBy>
- <FieldRef Name='Date' Ascending='FALSE' />
- </OrderBy>";
- usersOnListB = listB.GetItems(query);
- if(usersOnListB != null && usersOnListB.Count > 0)
- {
- // update date column in listA
- userListA["Date"] = DateTime.Parse(usersOnListB[0]["Date"].ToString());
- userListA.Update();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment