Below is the piece of code for accessing list items in a view of a Sharepoint List using CSOM.
To Access List Items in a Specific view of SharePoint List 2013
- ClientContext context = new ClientContext("http://mysites/");
- List list = context.Web.Lists.GetByTitle("Customer");
- context.Load(list);
- context.ExecuteQuery();
- View view = list.Views.GetByTitle("All Items");
- context.Load(view);
- context.ExecuteQuery();
- CamlQuery query = new CamlQuery();
- query.ViewXml = view.ViewQuery;
- ListItemCollection items = list.GetItems(query);
- context.Load(list);
- context.Load(items);
- context.ExecuteQuery();
- Console.Write(items.Count);
Here is the Code Snippet to get the Latest Version of a SharePoint List Item in SharePoint 2013.
- private SPListItem LatestVersionItem(SPListItem item)
- {
- if ((item.Versions != null) && (item.Versions.Count > 0))
- {
- SPListItemVersionCollection versions = item.Versions;
- SPListItem latestItemversion;
- if (item.Versions.Count > 1)
- latestItemversion= item.Versions[item.Versions.Count - 1].ListItem;
- else
- latestItemversion= item.Versions[0].ListItem;
- return latestItemversion;
- }
- else
- {
- return item;
- }
- }
No comments:
Post a Comment