ManagedProperty.Delete 方法 (Microsoft.Office.Server.Search.Administration)

Deletes the managed property from the search schema.

命名空间: Microsoft.Office.Server.Search.Administration
程序集: Microsoft.Office.Server.Search (在 microsoft.office.server.search.dll 中)

语法

声明
Public Sub Delete
用法
Dim instance As ManagedProperty

instance.Delete
public void Delete ()

备注

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.

示例

The following code example deletes a managed property from the search schema. For a more complete sample and explanation of the code, see 如何:删除托管属性.

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

另请参阅

参考

ManagedProperty 类
ManagedProperty 成员
Microsoft.Office.Server.Search.Administration 命名空间