Code Snippet: Determine the Type of the Parameter That a Filter is associated with
Applies to: SharePoint Server 2010
In this article
Description
Prerequisites
To use this example
Description
The following code example shows how to get the type of the parameter a filter is associated with using the BDC object model.
This code example is particularly useful when you want to provide the filter type in a client subscription file. The view.xml for external list views has a <Method> tag which says which finder method it is tied to. Under that it can have filter tags describing the filter information. You can use the following code example, given the method and filter name from the view.xml, to determine the parameter type the filter is associated with.
Prerequisites
Microsoft SharePoint Server 2010 or Microsoft SharePoint Foundation 2010 on the server.
Microsoft Office 2010 and Microsoft .NET Framework 3.5 on the client computer.
Microsoft Visual Studio.
At least one solution deployed to the BCS 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.Office.BusinessApplications.Runtime
Microsoft.BusinessData
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 the values of nameSpace , entityName, methodName, and filterName with valid values.
Save the project.
Compile and run the project.
RemoteSharedFileBackedMetadataCatalog remoteCatalog = new RemoteSharedFileBackedMetadataCatalog();
IEntity entity = remoteCatalog.GetEntity("<nameSpace>", "<entityName>");
string methodName = <methodName>; // Name of the method from view.xml
string filterName = <filterName>; // Name of the filter from view.xml
IMethodInstance mi = entity.GetMethodInstance(methodName, MethodInstanceType.Finder);
IFilterCollection viewFilters = mi.GetFilters();
IUserInputFilter filter = entity.Catalog.Helper.GetUserInputFilterByName(viewFilters, filterName);
Type filterType = filter.GetValueType();
MessageBox.Show(filterType.ToString());
See Also
Reference
RemoteSharedFileBackedMetadataCatalog
GetEntity(String, String)