Guest User

Untitled

a guest
Feb 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. using(SPSite site = new SPSite("https://yourspsite"))
  2. {
  3. using(SPWeb web = site.OpenWeb())
  4. {
  5. SPList listA = web.Lists["listA"];
  6. SPList listB = web.Lists["listB"];
  7.  
  8. // Assuming list A users are unique (based on your requirement)
  9. SPListItemCollection usersOnListA = listA.GetItems();
  10. SPListItemCollection usersOnListB;
  11. SPQuery query = new SPQuery();
  12. query.RowLimit = 1
  13. foreach(SPListItem userListA in usersOnListA)
  14. {
  15. // Get user on list B whose name is equal to user on list A, ordered descending by its date
  16. query.Query = @"<Where>
  17. <Eq>
  18. <FieldRef Name='Employee_x0020_Name' />
  19. <Value Type='Text'>"+ userListA["Emplloyee_x0020_Name"].ToString() +@"</Value>
  20. </Eq>
  21. </Where>
  22. <OrderBy>
  23. <FieldRef Name='Date' Ascending='FALSE' />
  24. </OrderBy>";
  25. usersOnListB = listB.GetItems(query);
  26. if(usersOnListB != null && usersOnListB.Count > 0)
  27. {
  28. // update date column in listA
  29. userListA["Date"] = DateTime.Parse(usersOnListB[0]["Date"].ToString());
  30. userListA.Update();
  31. }
  32. }
  33. }
  34. }
Add Comment
Please, Sign In to add comment