Step 1: Create
New Project. (Minimum .NET Framework 3.5)
Step 2: Add
“Microsoft.SharePoint.Client” and “Microsoft.SharePoint.Client.Runtime”
namespaces.
Step 3: Write
the following code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//SharePoint namespace
using Microsoft.SharePoint.Client;
namespace ReadingListItems
{
class Program
{
static void Main(string[]
args)
{
string
siteUrl = "http://sharepointserver.com";
ClientContext
clientContext = new ClientContext(siteUrl);
clientContext.Credentials = new System.Net.NetworkCredential("admin", "password",
"sharepointserver.com");
Web
site = clientContext.Web;
//Getting
List
List
list = site.Lists.GetByTitle("Students");
clientContext.Load(list);
clientContext.ExecuteQuery();
//Getting
List Items
CamlQuery
camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View/>";
ListItemCollection
listItemCollection = list.GetItems(camlQuery);
clientContext.Load(listItemCollection);
clientContext.ExecuteQuery();
//Printing
List Items
foreach
(ListItem listItem in
listItemCollection)
{
Console.WriteLine("Title: {0}, First Name: {1}, Last Name: {2}, Age:
{3}", listItem["Title"],
listItem["First Name"], listItem["Last Name"], listItem["Age"]);
}
Console.ReadLine();
}
}
}
Your post really cool and interesting. Thanks very much.
ReplyDeleteAsus - Vivobook 14" Touch-Screen Laptop - 6GB Memory - 500GB Hard Drive - Black
Asus - 10.1" Laptop - 2GB Memory - 320GB Hard Drive - Black (1015E-DS02)