Partilhar via


ManagedProperty.Delete Method

Deletes the managed property from the search schema.

Namespace:  Microsoft.Office.Server.Search.Administration
Assembly:  Microsoft.Office.Server.Search (in Microsoft.Office.Server.Search.dll)

Syntax

'Declaration
Public Sub Delete
'Usage
Dim instance As ManagedProperty

instance.Delete()
public void Delete()

Remarks

The Delete method can be called only for a managed property with no mappings; if there are still crawled properties mapped to the managed property, an error occurs with this method.

To prevent this error from occurring, call the DeleteAllMappings method before calling the Delete method.

You should also verify that the managed property can be deleted by checking the value of the DeleteDisallowed property. If this property is true, you cannot delete the managed property from the search schema.

Examples

The following code example deletes a managed property from the search schema. For a more complete sample and explanation of the code, see How to: Delete a Managed Property.

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.Collections;
using System.Text;
using Microsoft.Office.Server.Search.Administration;
using Microsoft.SharePoint;

namespace DeleteManagedPropertiesSample
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
   //Replace <ManagedPropertyName> with the name of the property to delete.
   string strName = "<ManagedPropertyName>";
    //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)
                {
                    if (property.Name == strName)
                    {
                        if (property.DeleteDisallowed)
                        {
                            Console.WriteLine("DeleteDisallowed enabled for " + strName + ".  Delete failed.");
  return;
                        }

                        property.DeleteAllMappings();
                        property.Delete();
                        Console.WriteLine(strName + " deleted.");
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

See Also

Reference

ManagedProperty Class

ManagedProperty Members

Microsoft.Office.Server.Search.Administration Namespace