ManagedPropertyCollection Class
Represents a collection of ManagedProperty objects.
Assembly: Microsoft.Office.Server.Search (in Microsoft.Office.Server.Search.dll)
Use the AllManagedProperties property of the Schema class to get the collection of managed properties in the Shared Service Provider's search schema.
To add a new managed property to the collection, use the Create() method.
Use an indexer to return a single managed property from the ManagedPropertyCollection object. For example, assuming the collection is assigned to a variable named mProperties, use mProperties[index] in Microsoft Visual C# or mProperties(index) in Microsoft Visual Basic, where index is a string containing the name of the managed property.
The following code example writes out the full list of managed properties to the console window. For a complete, step-by-step walkthrough of this sample code, see How to: Retrieve the Managed Properties for a Shared Service Provider.
Prerequisites
Ensure a Shared Service Provider is already created.
Project References
Add the following Project References in your console application code project before running this sample:
-
Microsoft.SharePoint
-
Microsoft.Office.Server
-
Microsoft.Office.Server.Search
using System; using System; using System.Collections.Generic; using System.Text; using Microsoft.Office.Server.Search.Administration; using Microsoft.SharePoint; namespace ManagedPropertiesSample { class Program { static void Main(string[] args) { try { //Replace <SiteName> with the name of a site using the Shared Service Provider. string strURL = "http://<SiteName>"; Schema sspSchema = new Schema(SearchContext.GetContext(new SPSite(strURL))); ManagedPropertyCollection properties = sspSchema.AllManagedProperties; foreach (ManagedProperty property in properties) { Console.WriteLine(property.Name); } } catch(Exception ex) { Console.WriteLine(ex.ToString()); } } } }
SPServiceContext serviceContext = SPServiceContext.GetContext(site);
SearchServiceApplicationProxy searchApplicationProxy = serviceContext.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy;
SearchServiceApplicationInfo searchApplictionInfo = searchApplicationProxy.GetSearchServiceApplicationInfo();
SearchServiceApplication searchApplication = SearchService.Service.SearchApplications.GetValue<SearchServiceApplication>(searchApplictionInfo.SearchServiceApplicationId);
Schema sspSchema = new Schema(searchApplication);
ManagedPropertyCollection managedProperties = sspSchema.AllManagedProperties;
User running the above code should have proper admin privilege on SSA. To do this select the SSA and in the Ribbon click administrators and add user as admin.
- 11/10/2011
- StephenDVick
- 5/4/2012
- Mallikarjun M
- 9/13/2011
- Ga-De