クライアントオブジェクトモデル - ドキュメントライブラリの更新メタデータ - 必要な値のないLookupフィールド

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

質問

クライアントオブジェクトモデルを使用して、ドキュメントライブラリ(またはリスト)内の文書のメタデータを更新しようとしています。私が手に入れていたエラーメッセージの数を辞めました、そして今新しい問題を打っています:

これらの項目のコンテンツタイプ内のメタデータフィールドの数はルックアップフィールドであり、それらの検索の数はマルチセレクトです。ただし、アプリケーションをテストする必要がありますが、「Metadataプロパティ[Sales Model Number]が必要な場合はSharePointからテストします。

マルチセレクトルックアップフィールドに空白の値を置くか、そうでなければこのエラーを回避するのですか?

    private void DoMetadataUpdateEx(DataRow row, ListItem item)
    {

        if (item.File != null || _sharePoint.CurrentList.ForceCheckout)
        {
            try
            {
                item.File.CheckOut();
                _sharePoint.Context.ExecuteQuery();
            }
            catch (Exception) { }
        }


        foreach (MetaMap mm in _metaMapping)
        {
            if (mm.ForceUse)
            {
                //Field f = _sharePoint.CurrentList.Fields.GetByInternalNameOrTitle(mm.SharePointColumn);
                Field f = _sharePoint.GetCurrentFieldByTitle(mm.SharePointColumn);
                switch (f.FieldTypeKind)
                {
                    case FieldType.MultiChoice:
                        string[] mcvals = row[mm.ExcelColumn].ToString().Split(',', ';');
                        item[f.InternalName] = mcvals;
                        break;
                    case FieldType.Lookup:
                        if((f as FieldLookup).AllowMultipleValues)
                        {
                            string[] mlvals = row[mm.ExcelColumn].ToString().Split(',', ';');
                            List<FieldLookupValue> newVals = new List<FieldLookupValue>();

                            FieldLookupValue[] oitemsalesmodelnum = (FieldLookupValue[])item[f.InternalName];
                            foreach (string ev in mlvals)
                            {
                                ListItem li = _sharePoint.GetLookupValue(f as FieldLookup, ev);
                                if (li == null)
                                {
                                    continue;
                                }
                                FieldLookupValue flv = new FieldLookupValue();
                                flv.LookupId = li.Id;

                                newVals.Add(flv);
                            }
                            if (newVals.Count > 0)
                            {
                                item[f.InternalName] = newVals.ToArray<FieldLookupValue>();
                            }
                            else
                            {
                                newVals.Add(new FieldLookupValue());
                                item[f.InternalName] = newVals.ToArray<FieldLookupValue>();
                            }
                        }
                        else
                        {
                            ListItem li = _sharePoint.GetLookupValue(f as FieldLookup, row[mm.ExcelColumn].ToString());
                            if (li != null)
                            {
                                FieldLookupValue flv = new FieldLookupValue();
                                flv.LookupId = li.Id;
                                item[f.InternalName] = flv;
                            }
                        }
                        break;
                    case FieldType.Computed:
                        throw new NotImplementedException("Computed columns are not yet implemented");
                    case FieldType.Integer:
                        item[f.InternalName] = Int32.Parse(row[mm.ExcelColumn].ToString());
                        break;
                    default:
                        item[f.InternalName] = row[mm.ExcelColumn].ToString();
                        break;

                }
            }
        }

        item.Update();
        //_sharePoint.Context.Load(item);
        item.Context.ExecuteQuery();


        if (item.File != null || _sharePoint.CurrentList.ForceCheckout)
        {
            try
            {
                item.File.CheckOut();
                _sharePoint.Context.ExecuteQuery();
            }
            catch (Exception)  // ignore checkout exception
            { }
            item.File.CheckIn("Modified by SP2010 Excel List Updater", CheckinType.MajorCheckIn);
            _sharePoint.Context.ExecuteQuery();
        }


    }// end DoMetadataUpdateEx()
.

*更新*

だから、ルックアップリストからルックアップリストへのルックアップから欠落していた値を追加することで、いくつかの変更を加え、同じエラーを得ました。そのため、フィールドに正当な値が割り当てられていて、まだこの「フィールドが必要」というエラーを投げています。楽しくない。私は感動の中で、現場のそれ自体に何か問題があることがあります...考えが考えていますか?私はおそらくもう少し前後に突き出して、フィールドを完全に削除して再作成します。

*更新2 *

もう少しデバッグを行うことは、次の発見に導きました。update()とexecuteQuery()呼び出しの後、その項目は元のメタデータに戻りますので、無効な値を適用している場合はエラーメッセージ。今私は本当に混乱しています。まず更新を実行しようとしてから後でチェックインするのではなく、同じExecuteQueryの間に更新とチェックインを実行する必要があります。

ありがとう、

  • マット
役に立ちましたか?

解決

OK、私は私の問題を解決したと思います。私は実際に2つのことが起こっているのがありました:

1)WCF接続は、別のWebアプリケーション(ASP.NET)にチェックイン時にメタデータ更新を伝播します。このサイトに必要なに関するメッセージを常に取得していました。ここで誰かがそれを理解することを期待しないでしょう。私はSharePointでフィールドを作成し、私が私のアプリケーションの更新をテストすることができるように、いくつかのデフォルトのボーガスの値を設定しました。

2)その問題を解決した後、私は物事が最後にチェックインし始めたことに気づいたが、フィールドのいかなる(まあ、1つ)が更新されていなかった。私はそれをもう少し和らげて、私がフィールドをループさせた毎回Update()コールをした場合、確かにSharePointでそれらを更新することがわかりました。Update()の呼び出しは、設定する最後のメタデータフィールド、またはそのようなものだけを更新していたようです。

新しいコード:

    private void DoMetadataUpdateEx(DataRow row, ListItem item)
    {
        ListItem updateItem = item;

        if (item.File != null || _sharePoint.CurrentList.ForceCheckout)
        {
            updateItem = item.File.ListItemAllFields;
            _sharePoint.Context.Load(updateItem);
            _sharePoint.Context.ExecuteQuery();
            try
            {
                item.File.CheckOut();
                _sharePoint.Context.ExecuteQuery();
            }
            catch (Exception) { }
        }

        foreach (MetaMap mm in _metaMapping)
        {
            if (mm.ForceUse)
            {
                //Field f = _sharePoint.CurrentList.Fields.GetByInternalNameOrTitle(mm.SharePointColumn);
                Field f = _sharePoint.GetCurrentFieldByTitle(mm.SharePointColumn);
                switch (f.FieldTypeKind)
                {
                    case FieldType.MultiChoice:
                        string[] mcvals = row[mm.ExcelColumn].ToString().Split(',', ';');
                        updateItem[f.InternalName] = mcvals;
                        break;
                    case FieldType.Lookup:
                        if((f as FieldLookup).AllowMultipleValues)
                        {
                            string[] mlvals = row[mm.ExcelColumn].ToString().Split(',', ';');
                            List<FieldLookupValue> newVals = new List<FieldLookupValue>();

                            FieldLookupValue[] oitemsalesmodelnum = (FieldLookupValue[])item[f.InternalName];
                            foreach (string ev in mlvals)
                            {
                                ListItem li = _sharePoint.GetLookupValue(f as FieldLookup, ev);
                                if (li == null)
                                {
                                    continue;
                                }
                                FieldLookupValue flv = new FieldLookupValue();
                                flv.LookupId = li.Id;

                                newVals.Add(flv);
                            }
                            if (newVals.Count > 0)
                            {
                                updateItem[f.InternalName] = newVals.ToArray<FieldLookupValue>();
                            }
                            else
                            {
                                newVals.Add(new FieldLookupValue());
                                updateItem[f.InternalName] = newVals.ToArray<FieldLookupValue>();
                            }
                        }
                        else
                        {
                            ListItem li = _sharePoint.GetLookupValue(f as FieldLookup, row[mm.ExcelColumn].ToString());
                            if (li != null)
                            {
                                FieldLookupValue flv = new FieldLookupValue();
                                flv.LookupId = li.Id;
                                updateItem[f.InternalName] = flv;
                            }
                        }
                        break;
                    case FieldType.Computed:
                        throw new NotImplementedException("Computed columns are not yet implemented");
                    case FieldType.Integer:
                        updateItem[f.InternalName] = Int32.Parse(row[mm.ExcelColumn].ToString());
                        break;
                    default:
                        updateItem[f.InternalName] = row[mm.ExcelColumn].ToString();
                        break;

                }
            }
            updateItem.Update();
        }

        //updateItem.Update();

        if (item.File != null || _sharePoint.CurrentList.ForceCheckout)
        {
            item.File.CheckIn("Modified by SP2010 Excel List Updater", CheckinType.MajorCheckIn);
        }
        else
        {
            _sharePoint.Context.ExecuteQuery();
        }
    }// end DoMetadataUpdateEx()
.

ライセンス: CC-BY-SA帰属
所属していません sharepoint.stackexchange
scroll top