如何从SharePoint中的自定义列表中删除字段,这些列表已通过“来自现有站点列的添加”菜单项添加?

sharepoint.stackexchange https://sharepoint.stackexchange.com/questions/248

  •  16-10-2019
  •  | 
  •  

我有一个自定义列表,并且通过单击列表的设置页面上的“来自现有站点列的添加”链接,添加了一个“页面图像”字段。我现在想删除字段,但是单击“设置”页面上的字段名称不会产生“删除”功能。

有帮助吗?

解决方案

“页面图像”是一种特殊的SharePoint字段,定义为 密封. 。这意味着一旦添加,就无法从UI中删除。但是,可以以编程方式将其删除:

SPList list = web.Lists["CustomTest"];
SPField f = list.Fields["Page Image"];
f.Sealed = false;
f.Update();
f.Delete();

作为参考,该字段定义在 C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\PublishingResources\PublishingColumns.xml.

归因信用:我 回答 在堆栈溢出上。

其他提示

除了被密封外,还可以读取一个字段,隐藏和等。所有这些因素都可能阻止该字段删除。删除列表字段的更合适的方法是以下一个:

public static bool RemoveField(SPField spField)
{
    if (spField == null)
    {
        WriteErrorToLog("spField is null! Please, provide a valid one");
        return false;
    }

    bool res = false;
    try
    {
        // check if it's a ReadOnly field.
        // if so, reset it
        if (spField.ReadOnlyField)
        {
            spField.ReadOnlyField = false;
            spField.Update();
        }

        // check if it's a Hidden field.
        // if so, reset it
        if (spField.Hidden)
        {
            spField.Hidden = false;
            spField.Update();
        }

        // check if the AllowDeletion property is set to false.
        // if so, reset it to true
        if (spField.AllowDeletion == null || !spField.AllowDeletion.Value)
        {
            spField.AllowDeletion = true;
            spField.Update();
        }

        // If the AllowDeletion property is set,
        // the Sealed property seems not to be examined at all.
        // So the following piece of code is commented.
        /*if(spField.Sealed)
        {
            spField.Sealed = false;
            spField.Update();
        }*/

        // If the AllowDeletion property is set,
        // the FromBaseType property seems not to be examined at all.
        // So the following piece of code is commented.
        /*if(spField.FromBaseType)
        {
            spField.FromBaseType = false;
            spField.Update();
        }*/

        // finally, remove the field
        spField.Delete();
        spField.ParentList.Update();

        res = true;
    }
    catch (Exception ex)
    {
        WriteErrorToLog(ex.Message);
    }

    return res;
}

public static bool RemoveField(SPList spList, string displayNameOrInternalNameOrStaticName)
{
    SPField spField = GetFieldByName(spList, displayNameOrInternalNameOrStaticName);
    if(spField == null)
    {
        WriteErrorToLog(string.Format("Couldn't find field {0}!", displayNameOrInternalNameOrStaticName));
        return false;
    }

    return RemoveField(spField);
}

public static void WriteErrorToLog(string errorMsg)
{
    // write error into log
}

阅读我的文章 如何以编程方式删除列表字段/列, , 了解更多。

当您添加SharePoint认为不可删除的字段时,我已经看到了这一点。

您可能必须以编程方式删除它或类似的工具 SharePointManager

如何使用管理内容类型隐藏字段?

列表设置 - >高级设置 - >允许管理内容类型单击内容类型 - >单击页面图像字段 - >选择“隐藏”?

  1. 首先转到默认页面中的家庭选项
  2. 单击您创建的列表名称。
  3. 单击“设置”选项卡窗格中的列表设置选项。
  4. 单击列中的列名选项
  5. 然后,您可以选择删除。按它,将被删除。
许可以下: CC-BY-SA归因
scroll top