The following methods determines whether list is already created or not in a site collection :
public static bool CheckIfListCreated(ClientContext context, string listName, ref string message)
{
try
{
ListCollection listCollection = context.Web.Lists;
context.Load(listCollection, lists => lists.Include(list => list.Title).Where(list => list.Title == listName));
context.ExecuteQuery();
if (listCollection.Count > 0)
{
message += listName + " " + string.Format("{0}", "Lists already exist.");
return true;
}
else
{
message += string.Empty;
return false;
}
}
catch (Exception ex)
{
throw ex;
}
}
Happy SharePointing..........................:)
No comments:
Post a Comment