0

2つの既存のコンテンツタイプに2つの新しいフィールドを追加しようとしていますが、この例外が発生しています。修正方法がわかりません。

次の行の最初のコンテンツタイプの更新後に例外がスローされます。agendaPoints.AddFieldRefFromContentType(currentWeb、fldRecurrent);

private void AddRecurrentAndCopyAttachmentsFieldsToContentType(SPWeb currentWeb)
        {

            try
            {
                currentWeb.AllowUnsafeUpdates = true;
                SPContentType agendaPointsProposedCT = currentWeb.ContentTypes[Meetings.Common.Constants.CONTENTTYPES_AGENDAPOINTPROPOSED_NAME];
                SPContentType agendaPoints = currentWeb.ContentTypes[Meetings.Common.Constants.CONTENTTYPES_AGENDAPOINT_NAME];

                string recurrentFieldName = currentWeb.Fields.Add(Meetings.Common.Constants.FIELDS_AGENDAPOINTSRECURRENT_NAME, SPFieldType.Boolean, false);
                SPField recurrentField = currentWeb.Fields.GetFieldByInternalName(recurrentFieldName);

                string copyAttachmentsFieldName = currentWeb.Fields.Add(Meetings.Common.Constants.FIELDS_AGENDAPOINTSCOPYATTACHMENTS_NAME, SPFieldType.Boolean, false);
                SPField copyAttachmentsField = currentWeb.Fields.GetFieldByInternalName(recurrentFieldName);

                SPField fldRecurrent = currentWeb.Fields[Meetings.Common.Constants.FIELDS_AGENDAPOINTSRECURRENT_NAME];
                SPField fldCopyAttachments = currentWeb.Fields[Meetings.Common.Constants.FIELDS_AGENDAPOINTSCOPYATTACHMENTS_NAME];

                agendaPointsProposedCT.AddFieldRefFromContentType(currentWeb, fldRecurrent);
                agendaPointsProposedCT.AddFieldRefFromContentType(currentWeb, fldCopyAttachments);
                MoveFieldInColumnOrder(currentWeb, Meetings.Common.Constants.CONTENTTYPES_AGENDAPOINTPROPOSED_NAME, fldRecurrent.InternalName, 1);
                MoveFieldInColumnOrder(currentWeb, Meetings.Common.Constants.CONTENTTYPES_AGENDAPOINTPROPOSED_NAME, fldCopyAttachments.InternalName, 2);
                agendaPointsProposedCT.Update();

                currentWeb.AllowUnsafeUpdates = true;
                agendaPoints.AddFieldRefFromContentType(currentWeb, fldRecurrent);
                agendaPoints.AddFieldRefFromContentType(currentWeb, fldCopyAttachments);                
                MoveFieldInColumnOrder(currentWeb, Meetings.Common.Constants.CONTENTTYPES_AGENDAPOINT_NAME, fldRecurrent.InternalName, 1);
                MoveFieldInColumnOrder(currentWeb, Meetings.Common.Constants.CONTENTTYPES_AGENDAPOINT_NAME, fldCopyAttachments.InternalName, 2);
                agendaPoints.Update();

            }
            catch (Exception ex)
            {

                throw;
            }
            finally
            {
                currentWeb.AllowUnsafeUpdates = false;
            }

        }

および拡張メソッド

public static void AddFieldRefFromContentType(this SPContentType contentType, SPWeb web,SPField field)
        {
            SPFieldLink fieldLink = new SPFieldLink(web.AvailableFields.GetField(field.InternalName));
            //Check if the Field reference exists
            if (!contentType.Fields.ContainsField(field.Title))
            {
                contentType.FieldLinks.Add(fieldLink);
                contentType.Update(true);
            }
            else
            {
                //Do Nothing
            }
        }
4

1 に答える 1

2

コンテンツタイプを取得する行を、[安全でない更新を許可する]の上/下の行に移動してみましたか。また、コンテンツタイプ間に継承設定のタイプはありますか?

于 2012-08-08T20:17:58.510 に答える