Share via


Creating external lists in SharePoint using Visual Studio

SharePoint shows us as they are storing data in lists. A list is an interface which displays and allows read write operations to a SQL Server/Express database called a “Content Database”. Business Connectivity Service is a service that facilitates connecting with the data that are located outside of the particular SharePoint site. Business Connectivity Services use External Content Types to make this possible in SharePoint. Then how about giving the SharePoint list experience to these external data? That is made possible with a concept called external list.

In this article I will be focusing on using Visual Studio to create an External Content Type and manually creating an external list from it.

Business Scenario

I need to display the blog articles published in the Microsoft Official Blog (http://blogs.microsoft.com/) with the article title, link to the article and the published date in a SharePoint list. To do this Microsoft has supported with an RSS feed provided as follows (http://blogs.microsoft.com/feed/). Since we do not need to fill the article with code I will create the external content type using Visual Studio, then deploy and show how to create a list manually. If needed, the list can be created using a feature receiver through C# code as well.

Prerequisites

Apart from the Visual Studio 2012/ 2013/ 2015 and a fully functional SharePoint Server, it is needed to ensure that Business Data Connectivity Service Application is installed and the service is activated. It is also possible to use SharePoint Designer and configure an external list with limited flexibility.

Creating the Visual Studio Solution

  1. Create a new project with ‘SharePoint 2013 – Empty Project’ template and name it as ‘MSBlogReader’. The solution should be a farm solution.
  2. Right click on the project in solution explorer and add a new ‘Business Data Connectivity Model (Farm Solution only)’ in the Office/ SharePoint section of the Add New Item window. Give the name as ‘MSBlogReaderModel’.
  3. Now you will see the new model added and two files named Entity1.cs and Entity1Service.cs added. Also if you double click on the MSBlogReaderModel.bdcm file. An object with the name Entity1 will appear in the BDC Designer. Once you click on top of it you might see the BDC Method Details window in bottom and the BDC Explorer window in the right side. If these windows are not available, they can be added by View --> Other Windows in Visual Studio.

Defining the BDC Entity

Now I need to understand the way how the list columns need to be displayed. Every SharePoint list item has an ID, then a Title. Apart from that I need two other columns for the link to the article and the published date. So the columns and the types of the list will be,

  • ID – int32
  • Title – string
  • LinkToArticle – string
  • PublishedDate – string
  1. Delete the ‘Entity1’ object in the BDC Designer. Then drag and drop a new Entity from the toolbox. Rename the Entity title as ‘BlogArticle’. Delete the existing Entity1Service.cs file and rename the EntityService.cs file to BlogArticleService.cs and Entity1.cs file to BlogArticle.cs in the solution explorer.

Replace the content in the BlogArticle class in the BlogArticle.cs (previously Entity1.cs) file with following properties.

1.public partial  class BlogArticle 
2.{
3.    public int  ID { get; set; }
4.    public string  Title { get; set; }
5.    public string  LinkToArticle{ get; set; }
6.    public string  PublishedDate { get; set; }
7.}

The components should look like in following image.

  1. Now go to the ‘BlogArticle’ entity in the BDC Designer and right click on the Identifiers section. Then click 'Add New Identifier'. Right click on the newly added ‘Identifier1’ and go to properties. Change the ‘Name’ property as 'ID' and 'Type Name' property as 'System.Int32'.
  2. Select the ‘BlogArticle’ entity again in the BDC Designer and go to BDC Method Details window. Expand the drop down and select 'Create Finder Method'. New set of options would appear in the BDC Method Detail window. Again expand the drop down and select 'Create Specific Finder Method'.

There should be two methods created in the BlogArticleService class named ReadList and ReadItem.

  1. Now select the BlogArticle entity in the BDC Designer and go to the BDC Explorer window. Expand the 'ReadList', then 'blogArticleList', then 'BlogArticleList'. 'BlogArticle' will be the end node. Right click it and go to properties then change the 'Type Name' property from 'System.String' to 'BlogArticle' from 'Current Project' tab.
  2. Go back to the 'BlogArticle' end node then right click on it and select 'Add type Descriptor'. Then go to properties and change Name property to 'ID' and Type Name property to 'System.Int32'. Then set the Identifier property as 'ID'.