Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. #r "Microsoft.SharePoint.Client.Runtime.dll"
  2. #r "Microsoft.SharePoint.Client.dll"
  3.  
  4. using System;
  5. using System.Security;
  6. using System.Configuration;
  7. using Microsoft.SharePoint.Client;
  8.  
  9. public static void Run(TimerInfo myTimer, TraceWriter log)
  10. {
  11.  
  12. string userName = ConfigurationManager.AppSettings["User"];
  13. string password = ConfigurationManager.AppSettings["Pass"];
  14. string spSite = ConfigurationManager.AppSettings["SharePointSiteUrl"];
  15. const string listName = "List00";
  16. const string listNameDestination = "List01";
  17.  
  18. log.Info($"Trigger function executed at: {DateTime.Now} with {userName} | {password} on {spSite}");
  19. using (ClientContext ctx = new ClientContext(spSite))
  20. {
  21. // Authenticating to SPO
  22. SecureString securePassword = new SecureString();
  23. foreach (char c in password.ToCharArray())
  24. securePassword.AppendChar(c);
  25. ctx.Credentials = new SharePointOnlineCredentials(userName, securePassword);
  26.  
  27. // Getting all SPO list items
  28. List myList = ctx.Web.Lists.GetByTitle(listName);
  29. CamlQuery query = CamlQuery.CreateAllItemsQuery(100);
  30. ListItemCollection collListItem = myList.GetItems(query);
  31. ctx.Load(collListItem);
  32. ctx.ExecuteQuery();
  33.  
  34. // Destination list item - create list items
  35. List destinationList = ctx.Web.Lists.GetByTitle(listNameDestination);
  36. ListItemCreationInformation itemCreateInfo;
  37.  
  38. foreach (ListItem oListItem in collListItem)
  39. {
  40. // Getting list item
  41. string customColumnValue = Convert.ToString(oListItem["CustomColumn"]);
  42. log.Info($" List Item retrieved from {listName} => {customColumnValue}");
  43.  
  44. // Writing values to destination list which are retrieved
  45. if (!string.IsNullOrEmpty(customColumnValue)){
  46. itemCreateInfo = new ListItemCreationInformation();
  47. ListItem newItem = destinationList.AddItem(itemCreateInfo);
  48. newItem["Title"] = customColumnValue;
  49. newItem.Update();
  50. log.Info($" Updating column Title with {listNameDestination} with {customColumnValue}");
  51. ctx.ExecuteQuery();
  52. }
  53.  
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement