magritton
10/8/2014 - 1:35 PM

C# code with CAML query to get all fields who is not a folder and a specific field is not null. This is SP2010 client object model.

C# code with CAML query to get all fields who is not a folder and a specific field is not null. This is SP2010 client object model.

string sQuery = @"<Query><Where><And><Neq><FieldRef Name='ContentType' /><Value Type='Text'>Folder</Value></Neq><IsNotNull><FieldRef Name='EmailSenderName'></FieldRef></IsNotNull></And></Where></Query>";
string sViewFields = @"<FieldRef Name=""SenderName"" />";
string sViewAttrs = @"Scope=""Recursive""";
uint iRowLimit = 10000;

var oQuery = new SPQuery();
oQuery.Query = sQuery;
oQuery.ViewFields = sViewFields;
oQuery.ViewAttributes = sViewAttrs;
oQuery.RowLimit = iRowLimit;

SPListItemCollection collListItems = oList.GetItems(oQuery);

foreach (SPListItem oListItem in collListItems)
{
}