Get ListItemCollection from SharePoint document list using CAML
ListItemCollection listItems = GetListItemCollectionFromSP("FileLeafRef", documentName, "Text", 1);
private static ListItemCollection GetListItemCollectionFromSP(string name, string value, string type, int rowLimit)
{
//Replace siteURL and documentListName with your SharePoint site URL and DocumentList
ListItemCollection listItems = null;
string siteURL = "site URL";
string documentListName = "document list";
using (ClientContext clientContext = new ClientContext(siteURL))
{
List documentsList = clientContext.Web.Lists.GetByTitle(documentListName);
CamlQuery camlQuery = new CamlQuery(); ;
camlQuery.ViewXml =
@"
" + value + @"
" + rowLimit.ToString() + @"
";
listItems = documentsList.GetItems(camlQuery);
clientContext.Load(documentsList);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
}
return listItems;
}
ListItemCollection listItems = GetListItemCollectionFromSP("FileLeafRef", documentName, "Text", 1);
private static ListItemCollection GetListItemCollectionFromSP(string name, string value, string type, int rowLimit)
{
//Replace siteURL and documentListName with your SharePoint site URL and DocumentList
ListItemCollection listItems = null;
string siteURL = "site URL";
string documentListName = "document list";
using (ClientContext clientContext = new ClientContext(siteURL))
{
List documentsList = clientContext.Web.Lists.GetByTitle(documentListName);
CamlQuery camlQuery = new CamlQuery(); ;
camlQuery.ViewXml =
@"
" + value + @"
" + rowLimit.ToString() + @"
";
listItems = documentsList.GetItems(camlQuery);
clientContext.Load(documentsList);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
}
return listItems;
}