---
title: "Read External List (BCS) from SharePoint 2010 using Client Object Model in C#"  
description: "In this article I am going to explain how you can access data in your BCS data source, by utilizing theClient Object Model.Go to Visual Studio 2010.Go"  
author: "Chris Anderson"  
published: 2011-12-13  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/847/read-external-list-bcs-from-sharepoint-2010-using-client-object-model-in-c-sharp  
category: "sharepoint"  
tags: ["sharepoint"]  
reading_time: 2 minutes  

---

# Read External List (BCS) from SharePoint 2010 using Client Object Model in C#

In this article I am going to explain how you can [access data](https://www.mindstick.com/forum/159853/how-to-access-data-using-entity-framework-in-asp-dot-net-mvc) in your BCS [data source](https://www.mindstick.com/forum/160659/how-do-you-create-a-custom-filter-to-filter-any-text-in-the-data-source-in-angularjs), by utilizing the **Client [Object Model](https://www.mindstick.com/forum/158432/what-is-the-document-object-model-dom-and-how-does-it-relate-to-web-development).**

- Go to [Visual Studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available) 2010.
- Go to File à New à Project.
- Select Windows [Application](https://www.mindstick.com/articles/12824/calculator-application-in-android) and apply the following settings to [your project](https://www.mindstick.com/forum/156583/best-way-to-link-bootstrap-file-in-your-project): \ [Target Framework](https://answers.mindstick.com/qa/31181/some-nuget-packages-were-installed-using-a-target-framework-different-from-the-current-target-framework-and-may-need-to-be-reinstalled): **.****NET 3.5**\ Build output: **AnyCpu (or x64)**
- Click Add.

![Read External List (BCS) from SharePoint 2010 using Client Object Model in C#](https://www.mindstick.com/mindstickarticle/9cd398f6-0e52-492b-ad5a-2d96cbea5eac/images/89a90159-95d8-4525-93cb-4c357f8ff414.png)

![Read External List (BCS) from SharePoint 2010 using Client Object Model in C#](https://www.mindstick.com/mindstickarticle/9cd398f6-0e52-492b-ad5a-2d96cbea5eac/images/0dc37d54-ba59-4893-9b29-19bbcc20e9ac.png)

Next, we need to add references to the Client Object Model in order to be able to work with the client-side APIs from our Windows Application.

Right click the “**References**” node and choose “**[Add Reference](https://www.mindstick.com/forum/548/how-to-add-reference-to-system-web-optimization)**”

![Read External List (BCS) from SharePoint 2010 using Client Object Model in C#](https://www.mindstick.com/mindstickarticle/9cd398f6-0e52-492b-ad5a-2d96cbea5eac/images/dd356e97-991e-42ab-9c31-51ed82d2d3d6.png)

· Choose **Browse**:

· Go to the following location: **C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI.**

· Select these two files:

**Microsoft.SharePoint.Client.dll**

**Microsoft.SharePoint.Client.Runtime.dll**

![Read External List (BCS) from SharePoint 2010 using Client Object Model in C#](https://www.mindstick.com/mindstickarticle/9cd398f6-0e52-492b-ad5a-2d96cbea5eac/images/32ea9532-f5a9-464a-ac6a-b483880db7e5.png)

Add the following controls in your Windows Application Form:

· A new [DataGridView](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) control

· A new [Button control](https://www.mindstick.com/articles/290/button-control-in-vb-dot-net)

![Read External List (BCS) from SharePoint 2010 using Client Object Model in C#](https://www.mindstick.com/mindstickarticle/9cd398f6-0e52-492b-ad5a-2d96cbea5eac/images/d2d3961a-59db-4db8-bffc-906e2df61786.png)

After adding controls you have to write the following code to access external list data:

```
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Linq;using System.Text;using System.Windows.Forms;using SP1 = Microsoft.SharePoint;using SP = Microsoft.SharePoint.Client; namespace AccessExternalListData{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }         private void button1_Click(object sender, EventArgs e)        {            // Define the Client Context (as defined in your textbox)            SP.ClientContext context = new SP.ClientContext("http://rohit:34143/");            SP.Web site = context.Web;             var StudentList = site.Lists.GetByTitle("StudentList");             SP.CamlQuery camlQuery = new SP.CamlQuery();             IQueryable<SP.ListItem> students = 
                                          StudentList.GetItems(camlQuery);
                                          StudentList.GetItems(camlQuery);            IEnumerable<SP.ListItem> externalList = context.LoadQuery(students);            context.ExecuteQuery();             var studentListData = from student in externalList              select new              {                  // We're never pointing to the field at the 0-index                  // because it's used by the BDC Identity itself. Hence our elements 
                     start at 1.
                     start at 1.                  StudentID = student.FieldValues.ElementAt(1).Value.ToString(),          
       StudentName = student.FieldValues.ElementAt(2).Value.ToString(),                  StudentCourse = student.FieldValues.ElementAt(3).Value.ToString()              };             // Simply clear the rows and columns of the GridView            gvStudents.Rows.Clear();            gvStudents.Columns.Clear();             // Add the columns we need (ProductID, Name, Description)            gvStudents.Columns.Add("StudentID", "StudentID");            gvStudents.Columns.Add("Name", "Name");          
             gvStudents.Columns.Add("Course", "Course");            foreach (var stud in studentListData)            {                // For each product in the list, add a new row to the GridView               gvStudents.Rows.Add(stud.StudentID, stud.StudentName, stud.StudentCourse);            }        }    }}
```

When you run this application and click on button (Display List) it will look something like this:

![Read External List (BCS) from SharePoint 2010 using Client Object Model in C#](https://www.mindstick.com/mindstickarticle/9cd398f6-0e52-492b-ad5a-2d96cbea5eac/images/8d0beece-ec1d-407a-8733-b2480e38d949.png)

Thanks for reading this article. I think this will help you a lot.

\

---

Original Source: https://www.mindstick.com/articles/847/read-external-list-bcs-from-sharepoint-2010-using-client-object-model-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
