Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
CAML QUERY to retrieve the items from a list using CSOM
WhatsApp
Gowtham Rajamanickam
9y
216.9
k
0
2
25
Blog
Here you can pass an undefined CamlQuery object to return all items from the list, or use the ViewXml property to define a CAML query and return items that meet specific criteria.The following example displays the ID, as well as the Title and Body column values, of the first 100 items in the NewBook list, starting with list items whose collection ID is greater than 19.
Steps
Open Visual Studio in your system
Select Console Applciation template and give as name "RetrieveListItems"
Add a Microsoft.Cleint Assembly refrence file in right side refrence tab in visual studio.
Replace Program.cs with the source code below.
using
System;
using
Microsoft.SharePoint.Client;
using
SP = Microsoft.SharePoint.Client;
namespace
Microsoft.SDK.SharePointServices.Samples
{
class
RetrieveListItems
{
static
void
Main()
{
string
siteUrl =
"http://gauti.sharepoint.com/sites/SP"
;
ClientContext clientContext =
new
ClientContext(siteUrl);
SP.List oList = clientContext.Web.Lists.GetByTitle(
"NewBook"
);
CamlQuery camlQuery =
new
CamlQuery();
camlQuery.ViewXml =
"<View><Query><Where><Geq><FieldRef Name='ID'/>"
+
"<Value Type='Number'>19</Value></Geq></Where></Query><RowLimit>100</RowLimit></View>"
;
ListItemCollection collListItem = oList.GetItems(camlQuery);
clientContext.Load(collListItem);
clientContext.ExecuteQuery();
foreach
(ListItem oListItem
in
collListItem)
{
Console.WriteLine(
"ID: {0} \nTitle: {1} \nBody: {2}"
, oListItem.Id, oListItem[
"Title"
], oListItem[
"Body"
]);
}
}
}
}
Hit F5 and see the magix happend in SharePoint 2013. Hope you have enjoyed this.!!! :-)
CAML QUERY to retrieving the items from a list using CSOM
Up Next
Update A List Item In SharePoint Using CSOM (Announcement List)
Ebook Download
View all
Getting Started with SharePoint Framework Development using TypeScript, PnP JS, and React JS
Read by 4.9k people
Download Now!
Learn
View all
Membership not found