using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;
namespace CreateFolders
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please enter the URL");
string strWebURL = Console.ReadLine();
Console.WriteLine(strWebURL);
ClientContext objContext = new ClientContext(strWebURL);
List objList = objContext.Web.Lists.GetByTitle("Programs");
ListItemCollection objListColl = objList.GetItems(new CamlQuery());
string[] entityCollection = { "List1", "List2", "List3" }; //List Name
objContext.Load(objListColl);
objContext.ExecuteQuery();
int batchCount = 30;
foreach (string entityName in entityCollection)
{
int i = 0;
List eachList = objContext.Web.Lists.GetByTitle(entityName);
ListItemCollection eachItemcollection = objContext.Web.Lists.GetByTitle(entityName).GetItems(new CamlQuery());
objContext.Load(eachList);
objContext.Load(eachItemcollection);
objContext.ExecuteQuery();
foreach (ListItem programItem in objListColl)
{
string itemid = programItem["ID"].ToString();
string title = programItem["Title"].ToString();
IEnumerable<ListItem> tempItem = eachItemcollection.AsEnumerable().Where(x => (x["Title"] != null && x["Title"].ToString() == itemid));
if (tempItem.Count() == 0)
{
ListItemCreationInformation itemInfo = new ListItemCreationInformation();
itemInfo.UnderlyingObjectType = FileSystemObjectType.Folder;
itemInfo.LeafName = itemid;
ListItem tempListItem = eachList.AddItem(itemInfo);
tempListItem["Title"] = itemid;
tempListItem["Program"] = itemid + ";#" + title;
tempListItem["Author"] = programItem["Author"];
tempListItem["Editor"] = programItem["Editor"];
tempListItem.Update();
i++;
if (i % batchCount == 0)
{
objContext.ExecuteQuery();
}
}
}
if (i % batchCount != 0)
{
objContext.ExecuteQuery();
}
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;
namespace CreateFolders
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please enter the URL");
string strWebURL = Console.ReadLine();
Console.WriteLine(strWebURL);
ClientContext objContext = new ClientContext(strWebURL);
List objList = objContext.Web.Lists.GetByTitle("Programs");
ListItemCollection objListColl = objList.GetItems(new CamlQuery());
string[] entityCollection = { "List1", "List2", "List3" }; //List Name
objContext.Load(objListColl);
objContext.ExecuteQuery();
int batchCount = 30;
foreach (string entityName in entityCollection)
{
int i = 0;
List eachList = objContext.Web.Lists.GetByTitle(entityName);
ListItemCollection eachItemcollection = objContext.Web.Lists.GetByTitle(entityName).GetItems(new CamlQuery());
objContext.Load(eachList);
objContext.Load(eachItemcollection);
objContext.ExecuteQuery();
foreach (ListItem programItem in objListColl)
{
string itemid = programItem["ID"].ToString();
string title = programItem["Title"].ToString();
IEnumerable<ListItem> tempItem = eachItemcollection.AsEnumerable().Where(x => (x["Title"] != null && x["Title"].ToString() == itemid));
if (tempItem.Count() == 0)
{
ListItemCreationInformation itemInfo = new ListItemCreationInformation();
itemInfo.UnderlyingObjectType = FileSystemObjectType.Folder;
itemInfo.LeafName = itemid;
ListItem tempListItem = eachList.AddItem(itemInfo);
tempListItem["Title"] = itemid;
tempListItem["Program"] = itemid + ";#" + title;
tempListItem["Author"] = programItem["Author"];
tempListItem["Editor"] = programItem["Editor"];
tempListItem.Update();
i++;
if (i % batchCount == 0)
{
objContext.ExecuteQuery();
}
}
}
if (i % batchCount != 0)
{
objContext.ExecuteQuery();
}
}
}
}
}