ManagedProperty.Delete 方法

从搜索架构中删除托管的属性。

命名空间:  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()

备注

可以调用Delete方法仅对托管属性与任何映射 ;如果那里仍已爬网属性映射到托管属性,使用这种方法就会出错。

若要避免出现此错误,请在调用Delete方法前调用DeleteAllMappings方法。

您还应该验证可以通过检查DeleteDisallowed属性的值中删除托管的属性。如果此属性为true,不能从搜索架构中删除托管的属性。

示例

下面的代码示例从搜索架构中删除托管的属性。更完整的示例和代码的说明,请参阅How to: Delete a Managed Property

Prerequisites

确保已创建了一个共享服务提供程序。

Project References

运行本示例之前,在控制台应用程序代码项目中添加以下项目引用:

  • 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 命名空间