Compartir a través de


: ManagedProperty.Delete (Método) (Microsoft.Office.Server.Search.Administration)

Deletes the managed property from the search schema.

Espacio de nombres:
Ensamblado: Microsoft.Office.Server.Search (in microsoft.office.server.search.dll)

Sintaxis

'Declaración
Public Sub Delete
'Uso
Dim instance As ManagedProperty

instance.Delete
public void Delete ()

Comentarios

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.

Ejemplo

The following code example deletes a managed property from the search schema. For a more complete sample and explanation of the code, see Procedimiento para eliminar una propiedad administrada.

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

Vea también

Referencia

ManagedProperty (Clase)
ManagedProperty (Miembros)
Microsoft.Office.Server.Search.Administration (Espacio de nombres)