0

Short and sweet : I'm parsing an XML document and adding new job openings into a sharepoint list as well as deleting them if the job id's and deleting them if the particular job id is not present in the list item collection.

Here's the question:

If i try to query a field value from the item collection that dosent exist, will that cause an error?

 foreach (ListItem listItem in items) 
 { 

     console.WriteLine(listItem["Title"]=="XYZ") // say, there is no item with a title "XYZ" 
  } 
Aman Gupta
  • 7,883
  • 5
  • 16
  • 24
  • Did you try it? :D I seem to remember I was getting exception about that, but it's pretty far. – Kilazur May 07 '14 at 12:10
  • 1
    I've read too fast, you obviously won't get an error in that specific exemple, since you will just print a `false boolean` (`listItem["Title"]=="XYZ" => false`) – Kilazur May 09 '14 at 07:08

1 Answers1

0

Let's say you're using this code:

var list = ctx.Web.Lists.GetByTitle(config.ListName); //ctx is your ClientContext
var collection = list.GetItems(SP.CamlQuery.CreateAllItemsQuery()); //using SP = Microsoft.SharePoint.Client;
ctx.Load(collection);
ctx.ExecuteQuery();
foreach (var item in collection)
{
    Console.WriteLine(item["Title"] == "XYZ");
}

It will not throw an exception, if the Title field is not == "XYZ" it will just print out False.

PsMaster
  • 131
  • 2
  • 10