다음을 통해 공유


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

  1. 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.

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

  3. In 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

      System.Windows.Forms

  7. 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;
    
  8. Replace the code in addin's startup event with the code listed at the end of this procedure.

  9. Replace the values of nameSpace , entityName, methodName, and filterName with valid values.

  10. Save the project.

  11. 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)

IEntity

GetMethodInstance(String, MethodInstanceType)

IMethodInstance

GetFilters()

IFilterCollection

IUserInputFilter

GetValueType()