Business Connectivity Service (BCS), enables users to read and write data from external systems - from web services, database, and Microsoft .NET Framework.
Following code snippet shows, how to access BCS object using Client Object Model
We already have BCS list named "Customer", contains columns Name, Address
// Specify your SharePoint Web Url
ClientContext clientContext = new ClientContext("http://contoso:3434");
// Specify SharePoint list name
List list = clientContext.Web.Lists.GetByTitle("Customer");
CamlQuery query = new CamlQuery();
query.ViewXml =
@" <View>
<ViewFields>
<FieldRef Name='Name'/>
<FieldRef Name='Address'/>
</ViewFields>
<Query>
<Where>
<Eq>
<FieldRef Name='Name'/>
<Value Type='Text'>Jhon</Value>
</Eq>
</Where>
</Query>
<RowLimit>100</RowLimit>
</View>";
ListItemCollection listItems = list.GetItems(query);
// Specify which field required to include in list object other wise it throws exception
clientContext.Load(
listItems, items => items.Include(
item => item["Name"], item => item["Address"]));
clientContext.ExecuteQuery();
foreach (ListItem listItem in listItems.ToList())
{
Console.WriteLine("{0} ==> {1}", listItem["Name"].ToString(), listItem["Address"].ToString());
}
No comments:
Post a Comment