Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #r "Microsoft.SharePoint.Client.Runtime.dll"
- #r "Microsoft.SharePoint.Client.dll"
- using System;
- using System.Security;
- using System.Configuration;
- using Microsoft.SharePoint.Client;
- public static void Run(TimerInfo myTimer, TraceWriter log)
- {
- string userName = ConfigurationManager.AppSettings["User"];
- string password = ConfigurationManager.AppSettings["Pass"];
- string spSite = ConfigurationManager.AppSettings["SharePointSiteUrl"];
- const string listName = "List00";
- const string listNameDestination = "List01";
- log.Info($"Trigger function executed at: {DateTime.Now} with {userName} | {password} on {spSite}");
- using (ClientContext ctx = new ClientContext(spSite))
- {
- // Authenticating to SPO
- SecureString securePassword = new SecureString();
- foreach (char c in password.ToCharArray())
- securePassword.AppendChar(c);
- ctx.Credentials = new SharePointOnlineCredentials(userName, securePassword);
- // Getting all SPO list items
- List myList = ctx.Web.Lists.GetByTitle(listName);
- CamlQuery query = CamlQuery.CreateAllItemsQuery(100);
- ListItemCollection collListItem = myList.GetItems(query);
- ctx.Load(collListItem);
- ctx.ExecuteQuery();
- // Destination list item - create list items
- List destinationList = ctx.Web.Lists.GetByTitle(listNameDestination);
- ListItemCreationInformation itemCreateInfo;
- foreach (ListItem oListItem in collListItem)
- {
- // Getting list item
- string customColumnValue = Convert.ToString(oListItem["CustomColumn"]);
- log.Info($" List Item retrieved from {listName} => {customColumnValue}");
- // Writing values to destination list which are retrieved
- if (!string.IsNullOrEmpty(customColumnValue)){
- itemCreateInfo = new ListItemCreationInformation();
- ListItem newItem = destinationList.AddItem(itemCreateInfo);
- newItem["Title"] = customColumnValue;
- newItem.Update();
- log.Info($" Updating column Title with {listNameDestination} with {customColumnValue}");
- ctx.ExecuteQuery();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement