I am creating a console application to display items in a List of SharePoint 2013 using Client Context.
This is my Code:
static void Main(string[] args) { string EmployeeName=""; string siteUrl = "http://siteUrl"; // Starting with ClientContext, the constructor requires a URL to the // server running SharePoint. using (ClientContext context = new ClientContext(siteUrl)) { //// The SharePoint web at the URL. Web web = context.Web; //// We want to retrieve the web's properties. context.Load(web); List list = context.Web.Lists.GetByTitle("Employee Name"); CamlQuery query = CamlQuery.CreateAllItemsQuery(100); ListItemCollection items = list.GetItems(query); context.Load(list); //// Execute the query to the server. context.ExecuteQuery(); foreach (ListItem listItem in items) { EmployeeName = EmployeeName + ", " + listItem["Title"]; } Console.WriteLine(EmployeeName); } }
When i debug through the application i found that context object threw an exception as
ServerVersion = 'context.ServerVersion' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
I am the site collection administrator, so no problem of Permission to read the list.