Code Snippet: Enumerate Items of an External Content Type in the Client Cache
Applies to: SharePoint Server 2010
In this article
Description
Prerequisites
To use this example
Description
The following code example shows how to enumerate the items of an external content type in the client cache.
Prerequisites
Microsoft SharePoint Server 2010 or Microsoft SharePoint Foundation 2010 on the server.
Microsoft Office Professional Plus 2010 and Microsoft .NET Framework 3.5 on the client computer.
Microsoft Visual Studio.
At least one subscription in the Business Connectivity Services client cache.
To use this example
Start Visual Studio on the client computer and create a C# Office application add-in project. Select .NET Framework 3.5 when you create the project.
From the View menu, click Property Pages to bring up the project properties.
In the Build tab, for the Platform target, select Any CPU.
Close the project properties window.
In Solution Explorer, under References, remove all project references except for System and System.Core.
Add the following references to the project:
Microsoft.BusinessData
Microsoft.Office.BusinessApplications.Runtime
System.Windows.Forms
Replace the existing using statements with the following statements.
using System; using Microsoft.BusinessData.MetadataModel; using Microsoft.Office.BusinessData.MetadataModel; using Microsoft.BusinessData.Runtime; using System.Windows.Forms;
Replace the code in addin's startup event with the code listed at the end of this procedure.
Replace <entityName>, <namespace>, <IdentityField>, and <Field1> with valid values.
Save the project.
Compile and run the project.
This should open the Office application and display the messages printed from this code.
RemoteSharedFileBackedMetadataCatalog RemoteCatalog = new
RemoteSharedFileBackedMetadataCatalog();
IEntity remoteEntity = RemoteCatalog.GetEntity(
"<namespace>", "<entityName>");
ILobSystemInstance LobSysteminstance =
remoteEntity.GetLobSystem().GetLobSystemInstances()[0].Value;
IMethodInstance method = remoteEntity.GetMethodInstance(
"Read List", MethodInstanceType.Finder);
IEntityInstanceEnumerator ieie = remoteEntity.FindFiltered(
method.GetFilters(), LobSysteminstance);
IView view = remoteEntity.GetFinderView(method.Name);
while (ieie.MoveNext())
{
MessageBox.Show(String.Format(
"Id: {0}, Field1: {1}",
ieie.Current["<IdentityField>"],
ieie.Current["<Field1>"]));
}
See Also
Reference
RemoteSharedFileBackedMetadataCatalog
GetEntity(String, String)
GetMethodInstance(String, MethodInstanceType)