Thursday, June 26, 2014

Create an External List Using C#





1. In the feature reciever I added following constants.

private const string ListName = "MyExternalList";
private const string ListDescription = "External list containing service types for each client";
private const string ListUrlFormat = "Lists/{0}";

private const string LobSystemInstanceValue = "VSDemoModel";
private const string EntityNamespaceValue = "BCSVSDemo.VSDemoModel";
private const string EntityValue = "Entity1";
private const string SpecificFinderValue = "ReadItem";

I will go through some explanation on what are the last 3 constants are. 

LobSystemInstanceValue --> Give the name you gave when creating the BDC model. It will appear in the solution explorer.
EntityNamespaceValue --> Namespace of the class that the entity class is available.
EntityValue --> Name of the entity which includes the properties.
SpecificFinderValue --> The method that maps for reading an item. The method name which is 'ReadItem' by default.

2. Then in the feature activation I added the following code.

SPListDataSource ds = new SPListDataSource();

using (SPSite site = new SPSite("http://uglwfe/sites/APT"))
   using (SPWeb web = site.RootWeb)
      SPList externalList = web.Lists.TryGetList(Feature1FeatureEventReceiver.ListName);

      if (externalList == null)
         string listUrl = string.Format(


Now activate the second feature (one with the event receiver) after activating the feature included the BDC model. Make sure the proper rights are set in the external content type so that can be accessed by necessary users.  

1 comment:

  1. I'm only vaguely familiar with C# but with your help I was able to figure this out! Thanks!

    Fred | IT Support Mansfield