Code Snippet: Programmatically Request a Cache Refresh on the Client
Applies to: SharePoint Server 2010
In this article
Description
Prerequisites
To use this example
Description
The following code example shows how to programmatically do a cache refresh from a client application. When run, this code starts the BCSSync service if it is not already running and requests a refresh in the BDC client cache.
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
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.
From the View menu, select Property Pages to bring up the project properties.
On 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.Office.BusinessApplications.Runtime
Microsoft.BusinessData
Replace the existing using statements with the following statements:
using System; using Microsoft.BusinessData.Offlining; using Microsoft.Office.BusinessData.Offlining;
Replace the code in the add-in’s startup event with the code listed at the end of this procedure.
Replace the placeholder values of <entityNamespace>, <entityName>, <viewName>, and <subscriptionName> with valid values.
Save the project.
Compile and run the project.
This opens the Office application and executes the following code.
RemoteOfflineRuntime offlineRuntime = new RemoteOfflineRuntime();
ISubscriptionManager subManager = offlineRuntime.GetSubscriptionManager();
ISubscription sub = subManager.GetSubscription("<EntityNameSpace>", "<EntityName>", "<ViewName>", "<SubscriptionName>");
sub.RequestRefresh(true);
See Also
Reference
RemoteOfflineRuntime
GetSubscriptionManager()