Thursday, June 19, 2014

Create SharePoint 2013 External List using Visual Studio 2012

Business Connectivity Services (BCS) are meant to provide access to data that relies out of the SharePoint environment. It can be a Web Service, SQL database, or even a .NET collection. The good thing about BCS is that it gives the real SharePoint feeling when external data is linked up with it. The data can be indexed to Search, Event Receivers(remote), Look and Feel, CRUD operations and etc... 

The important key element that comes with the BCS is 'External Content Type'. It handles the connectivity between SharePoint and external data source. 

The main focus of this article will be on how to deploy a BCS solution using Visual Studio 2013 for SharePoint 2013. 

1. Create a 'SharePoint 2013 - Empty' project in Visual Studio and name it as 'BCSVSDemo'. 

Click the 'OK' button and you will be navigated to the 'SharePoint Customization Wizard'. Mention the site URL and select the option 'Deploy as a farm solution'. Click 'Finish' button in order to complete project creation.


2. Right click on project in the solution explorer and Add --> New Item --> Business Data Connectivity Model (farm Solution only). Type the name as 'VSDemoModel'.

Click 'Add' button to add the Model to solution. 

The designer will show an entity as 'Entity1' and the Model adds 2 new classes 'Entity1.cs' and 'Entity1Service.cs'. Also open BDC Method Details window. If not available by default, open it from VIEW --> Other Windows --> BDC Method Details.


You can rename 'Entity1' to whatever the entity you need such as 'Contact', 'Application' and etc...

3. Replace the 'Entity1Service.cs' class with following code. 


What I have done here is creating a static variable and populating it with two Entity1 type objects. ReadList method is associated with displaying the list items in the list view. ReadItem method is associated with displaying the item content in the list item display view. 

4. Deploy the solution to SharePoint site by right click the solution and selecting 'Deploy Solution'.

Navigate to 'Site Content' and click 'add an app'. You will be navigated to Your Apps page. Select 'External List' template from the set of list templates. 'Adding External List' window will be open. Give the Name as 'BCSVS List' and pick 'VSDemoModel' from 'External Content Type Picker'. 


5. Navigate to 'BCSVS List' and you will see 2 list items in it. 


Important: 

1. In case, you try to add new items to the list or edit an item, you will see the options are disabled in the ribbon. The reason is that we have only 2 methods defined in the content type. 'ReadList' and 'ReadItem'. In order to add edit and create new options you need to write implementations in the same Entity1Service.cs calss. Will cover that in the next article.

2. If you are connecting a SQL data source or a WCF Service, you can write the implementations in the 'ReadList' and 'ReadItem' methods. Best suggested option is adding a 'LINQ to SQL' item to the project. 

The Demo Solution can be downloaded from here.


2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. I also use Ideals virtual data room. It is very efficient service for deals implementation and data management.

    ReplyDelete