Export (0) Print
Expand All

How to: Retrieve the Managed Properties for a Shared Services Provider

SharePoint 2007

The Schema object in the Enterprise Search Administration object model provides access to the managed properties configured for the search service of a Shared Services Provider (SSP).

The following procedure shows how to write the full list of managed properties and their property identifiers (PIDs), from a console application.

To display the list of managed property names and PIDs from a console application

  1. In your application, set references to the following DLLs:

    • Microsoft.SharePoint.dll

    • Microsoft.Office.Server.dll

    • Microsoft.Office.Server.Search.dll

  2. In the class file of your console application, add the following using statements near the top of the code with the other namespace directives.

    using Microsoft.SharePoint;
    using Microsoft.Office.Server.Search.Administration;
    
  3. To retrieve the Schema object for the search context of the SSP, add the following code. For more information about ways to retrieve the search context, see How to: Return the Search Context for the Search Service Provider.

    /*
    Replace <SiteName> with the name of a site using the SSP
    */
    string strURL = "http://<SiteName>";
    SearchContext context;
    using (SPSite site = new SPSite(strURL))
    {
        Context = SearchContext.GetContext(site);
    }
    Schema sspSchema = new Schema(context);
    
  4. Retrieve the collection of managed properties by using the following code:

    ManagedPropertyCollection properties = sspSchema.AllManagedProperties;
    
  5. To loop through the managed properties, and display the name and PID for each property, add the following code.

    foreach (ManagedProperty property in properties)
    {
        Console.WriteLine(property.Name + "  PID: " + property.PID);
    }
    

Example

Following is the complete code for the console application class sample.

Prerequisites

  • Ensure that a Shared Services 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.Collections;
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 SSP
                */
                string strURL = "http://<SiteName>";
                SearchContext context;
                using (SPSite site = new SPSite(strURL))
                {
                    Context = SearchContext.GetContext(site);
                }
                Schema sspSchema = new Schema(context);
                ManagedPropertyCollection properties = sspSchema.AllManagedProperties;
                foreach (ManagedProperty property in properties)
                {
                    Console.WriteLine(property.Name + "  PID: " + property.PID);
                }
            }
            catch(Exception ex)
            {
                 Console.WriteLine(ex.ToString());
            }
        }
    }
}

See Also

Community Additions

ADD
Show:
© 2014 Microsoft