Partager via


ManagedProperty.Delete, méthode (Microsoft.Office.Server.Search.Administration)

Deletes the managed property from the search schema.

Espace de noms : Microsoft.Office.Server.Search.Administration
Assembly : Microsoft.Office.Server.Search (dans microsoft.office.server.search.dll)

Syntaxe

'Déclaration
Public Sub Delete
'Utilisation
Dim instance As ManagedProperty

instance.Delete
public void Delete ()

Remarques

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.

Exemple

The following code example deletes a managed property from the search schema. For a more complete sample and explanation of the code, see Procédure : supprimer une propriété gérée.

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());
            }
        }
    }
}

Voir aussi

Référence

ManagedProperty, classe
Membres ManagedProperty
Microsoft.Office.Server.Search.Administration, espace de noms