代码之家  ›  专栏  ›  技术社区  ›  Ryan Shripat Simon_Weaver

如何删除自定义列表中从现有站点列添加的列?

  •  1
  • Ryan Shripat Simon_Weaver  · 技术社区  · 17 年前

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

    3 回复  |  直到 17 年前
        1
  •  3
  •   Alex Angas Colin    17 年前

    “页面图像”是一种特殊的SharePoint字段,定义为 密封的

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

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

        2
  •  2
  •   Makyen Luke Bakken    6 年前

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

    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
    }
    

    通读 article on my blog ,以了解更多。

        3
  •  1
  •   gn22    17 年前
    1. 在单选字段“允许管理内容类型”中,单击“是”,然后返回文档库设置

    2. 在名为“内容类型”的新部分下,单击“文档”