Saturday, November 19, 2011

Alternative ways to programmatic read contents of External List with filtered view

In order to export the displayed contents of a BCS External List to Excel (see previous post), I first have to programmatically retrieve the contents in custom code. The External List has a filter applied to it's Finder method, set via the default SPView:
My first thought was therefore that below code should retrieve the same filtered external data as when rendering the BCS External List on a SharePoint page:
However, GetItems returns an empty collection. Upon debugging the called GetNotifications webservice method, I discovered that the filter-param always has value ‘null’. To me unclear why, since it has been set in the DefaultView.
However, although this approach works; it left me rather dissatisfied. Conceptually I want to export the contents of the same (External) List that I already have provisioned on a SharePoint page; so why should I have to dive under the BCS hood to get the same contents? Also, this code is very much aware / coupled to BCS API, while the 'Export SPList to Excel' functionality on itself is general. Thus, with some ample time available, I decided to analyze the way in which the standard XsltViewWebPart is issuing the external data retrieval – using JetBrains DotPeek reflector tool (as .NET Reflector is no longer free of licensee charge). It appears that this is done slightly different as my original attempt:
Not only is the code LOC of this far less, but also this code is general; applicable for both regular SharePoint lists as BCS External Lists.


  1. Check out this helpful link too...

    Its also having a wonderful post on Read External List (BCS) from SharePoint 2010 using Client Object Model in C#.


  2. Hi,

    Noteworthy that within the ClientOM code it is transparent that this SharePoint list is actually a 'window' to external data. That is also the basis of my first approach (list.GetItems). However, the extension was required to apply the filter in the Finder method, despite the presence of the filter-value in the defaultView.
    What is the effect of a filter in the Finder method in case of ClientOM code; do you still get results with this simple code, or is then also an extension as for the server-side code required?