「既存のサイト列から追加」メニュー項目を介して追加されたSharePointのカスタムリストからフィールドを削除するにはどうすればよいですか?

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

  •  16-10-2019
  •  | 
  •  

質問

カスタムリストがあり、リストの[設定]ページの[既存のサイト列からの追加]リンクをクリックして[ページ画像]フィールドを追加しました。フィールドを削除したいのですが、[設定]ページのフィールド名をクリックすると、「削除」機能が生じません。

役に立ちましたか?

解決

「ページイメージ」は、 密閉. 。これは、追加されたら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帰属
所属していません sharepoint.stackexchange
scroll top