Skip to content

Instantly share code, notes, and snippets.

@andyhuey
Created December 17, 2016 00:29
Show Gist options
  • Save andyhuey/c5a25484c3fb1efcf1b4a3eaf388795b to your computer and use it in GitHub Desktop.
Save andyhuey/c5a25484c3fb1efcf1b4a3eaf388795b to your computer and use it in GitHub Desktop.
a bit of SharePoint CSOM code
private bool doesVendorRecExist(string companyCode, string vendorNum,
List vendorList, ClientContext cc)
{
CamlQuery spq = new CamlQuery();
spq.ViewXml = string.Format(@"
<View><Query>
<Where><And>
<Eq><FieldRef Name='VendorNo' /><Value Type='Text'>{0}</Value></Eq>
<Eq><FieldRef Name='CompanyName' /><Value Type='Text'>{1}</Value></Eq>
</And></Where>
</Query></View>", vendorNum, companyCode);
ListItemCollection myItems = vendorList.GetItems(spq);
cc.Load(myItems);
try
{
cc.ExecuteQuery();
}
catch (Microsoft.SharePoint.Client.ServerException ex)
{
Console.WriteLine("Error in doesVendorRecExist({0},{1}): {2}", companyCode, vendorNum, ex.Message);
Environment.Exit(-1);
}
return (myItems.Count > 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment