/// <summary> /// Get all items from an specified folder that match the specified criteria /// </summary> /// <param name="folder">Folder relative to list root. For example: if the folder is Lists/Orders/US, the parameter should be US</param> /// <param name="pagingInfo">Paging info string returned from a previous execution</param> /// <param name="pageSize">Page size for the query</param> /// <param name="camlQuery">Search criteria in CAML format starting from the <Where> clause</param> /// <returns>Returns paged list of domain objects</returns> public SharePointPagedData <TEntity> GetAllFromFolder(string folder, string pagingInfo = null, uint pageSize = 10, string camlQuery = null) { Logger.Logger.Debug("SharePointRepository.GetAllFromFolder", "Folder = {0}, PagingInfo = {1}, PageSize = {2}, CamlQuery = {3}", folder, pagingInfo, pageSize, camlQuery); SharePointPagedData <TEntity> result = Call(() => { using (_context.Web) { // disable schema caching _context.Web.CacheAllSchema = false; // access source list var list = GetSourceList(); // build all items query var spQuery = new SPQuery(); var spFolder = FindFolder(folder); if (spFolder != null) { spQuery.Folder = spFolder; } if (!string.IsNullOrWhiteSpace(camlQuery)) { spQuery.Query = camlQuery; } // execute all items query var items = list.GetItems(spQuery); var originalItems = items; // count total items var totalItems = items.Count; // set new row limit RowLimit = pageSize > totalItems ? (uint)totalItems : pageSize; if (spFolder != null) { spQuery = new SPQuery() { RowLimit = RowLimit, Folder = spFolder }; } else { spQuery = new SPQuery() { RowLimit = RowLimit }; } if (!string.IsNullOrWhiteSpace(camlQuery)) { spQuery.Query = camlQuery; } // paged search if (!string.IsNullOrWhiteSpace(pagingInfo)) { spQuery.ListItemCollectionPosition = new SPListItemCollectionPosition(pagingInfo); } // execute actual query items = list.GetItems(spQuery); if (items.ListItemCollectionPosition != null && RowLimit > 0) { pagingInfo = items.ListItemCollectionPosition.PagingInfo; } else { pagingInfo = string.Empty; } return(new SharePointPagedData <TEntity>(originalItems, PopulateItems(items), pagingInfo, RowLimit)); } }); return(result); }
/// <summary> /// Get all items that match the specified criteria /// </summary> /// <param name="pagingInfo">Paging info string returned from a previous execution</param> /// <param name="pageSize">Page size for the query</param> /// <param name="camlQuery">Search criteria in CAML format starting from the <Where> clause</param> /// <returns>Returns paged list of domain objects</returns> public SharePointPagedData <TEntity> GetAll(string pagingInfo, uint pageSize = 10, string camlQuery = null) { Logger.Logger.Debug("SharePointRepository.GetAll", "PagingInfo = {0}, Query = {1}", pagingInfo, camlQuery); SharePointPagedData <TEntity> result = Call(() => { using (_context.Web) { _context.Web.CacheAllSchema = false; // access source list var list = GetSourceList(); // build all items query var query = new SPQuery(); if (!string.IsNullOrEmpty(camlQuery)) { query.Query = camlQuery; } var items = list.GetItems(query); var originalItems = items; // count total items var totalItems = originalItems.Count; // set new row limit RowLimit = pageSize > totalItems ? (uint)totalItems : pageSize; query = new SPQuery() { RowLimit = RowLimit }; if (!string.IsNullOrEmpty(camlQuery)) { query.Query = camlQuery; } // paged search if (!string.IsNullOrEmpty(pagingInfo)) { query.ListItemCollectionPosition = new SPListItemCollectionPosition(pagingInfo); } // execute query items = list.GetItems(query); if (items.ListItemCollectionPosition != null && RowLimit > 0) { pagingInfo = items.ListItemCollectionPosition.PagingInfo; } else { pagingInfo = string.Empty; } return(new SharePointPagedData <TEntity>(originalItems, PopulateItems(items), pagingInfo, RowLimit)); } }); return(result); }