Code Snippet: Get Members of a BCS Cache Subscription 2

Applies to: SharePoint Server 2010

In this article
Description
Prerequisites
To use this example

Description

The following example shows how to get the members of a Business Connectivity Services cache subscription on the client.

Prerequisites

  • Microsoft SharePoint Server 2010 or Microsoft SharePoint Foundation 2010 installed on the server

  • Microsoft Office Professional Plus 2010 and Microsoft .NET Framework 3.5 installed on the client computer

  • Microsoft Visual Studio

  • At least one subscription in the Business Connectivity Services Client Cache

To use this example

  1. Start Visual Studio on the client computer, and then create a new C# Microsoft Office application add-in project. Select .NET Framework 3.5 when you create the project.

  2. From the View menu, select Property Pages to bring up the project properties.

  3. On the Build tab, for the Platform target, select Any CPU.

  4. Close the project properties window.

  5. In Solution Explorer, under References, remove all project references except for System and System.Core.

  6. Add the following references to the project:

    1. Microsoft.Office.BusinessApplications.Runtime

    2. Microsoft.BusinessData

    3. System.Windows.Forms

  7. Replace the existing using statements with the following statements:

    using System;
    using Microsoft.BusinessData.Offlining;
    using Microsoft.Office.BusinessData.Offlining;
    using System.Windows.Forms;
    using System.Collections.Generic;
    using Microsoft.BusinessData.Runtime;
    
  8. Replace the code in the add-in’s startup event with the code listed at the end of this procedure.

  9. Replace the placeholder values of <entityNamespace>, <entityName>, <viewName>, and <subscriptionName> with valid values.

  10. Save the project.

  11. Compile and run the project.

    This opens the Office application and displays the messages printed from this code.

RemoteOfflineRuntime remoteOfflineRuntime = new RemoteOfflineRuntime();

// Read the subscription.
ISubscription sub = 
    remoteOfflineRuntime.GetSubscriptionManager().GetSubscription(
    "<entityNamespace>", "<entityName>", "<viewName>", "<subscriptionName>");

//Get subscription members.
using (IEnumerator<IEntityInstance> subMembers = sub.GetMembers())
{
    while (subMembers.MoveNext())
    {
        //Get the Synchronization Status of each member.
        MessageBox.Show((((IOfflineEntityInstance)subMembers.Current).SynchronizationStatus).ToString());
    }
}

See Also

Reference

RemoteOfflineRuntime

GetSubscriptionManager()

ISubscription

GetSubscription(String, String, String, String)

GetMembers()