1

現在のシナリオでは、あるライブラリから別のライブラリにドキュメントセットをコピーしようとしていますが、必要なのはdocsetプロパティのみであり、コンテンツは必要ないため、DocumentSet.Importを使用できません。

このコードのSystem.Updateで例外がスローされます。

private void CopyAgendaPointToRootSite(SPListItem agendaPointItem, string oldReasonReturned)
        {

            try
            {
                if (agendaPointItem != null)
                {
                    SPWeb currentSite = agendaPointItem.ParentList.ParentWeb;
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPSite site = new SPSite(currentSite.Site.RootWeb.Url))
                        {
                            using (SPWeb elevatedTargetWeb = site.OpenWeb())
                            {
                                SPList targetList = GetAgendaPointProposedTargetLibrary(agendaPointItem, elevatedTargetWeb);
                                SPDocumentLibrary targetDocumentLibrary = (SPDocumentLibrary)targetList;

                                SPContentTypeId targetCTId = targetList.ContentTypes.BestMatch(new SPContentTypeId(MeetingsCommon.Constants.CONTENTTYPES_AGENDAPOINTPROPOSED_ID));
                                DocumentSet documentSet = DocumentSet.GetDocumentSet(agendaPointItem.Folder);
                                if (documentSet != null)
                                {
                                    string strAgendaPointTitle = agendaPointItem[MeetingsCommon.Constants.FIELDS_AGENDAPOINTTITLENL_NAME] +
                                        " / " + agendaPointItem[MeetingsCommon.Constants.FIELDS_AGENDAPOINTTITLEFR_NAME];

                                    SPListItemCollection colProposedItems = FindAgendaPointProposedItem((SPDocumentLibrary)targetList, documentSet.Item.Name);
                                    if (colProposedItems.Count > 0)
                                        throw new Exception(string.Format(HelperFunctions.GetResourceString(
                                            MeetingsCommon.Constants.RESOURCES_FILE_NAME,
                                            "Message_AgendaPointsEvents_ERROR_DocumentSetAlreadyExistsInRootSite2"), strAgendaPointTitle));



                                    using (DisableItemEventScope scope = new DisableItemEventScope())
                                    {
                                        DocumentSet docSetCreated = DocumentSet.Create(targetList.RootFolder, agendaPointItem.Name, targetCTId, new Hashtable(), true);
                                        SPListItem listItem = docSetCreated.Item;

                                        foreach (SPField field in agendaPointItem.Fields)
                                        {
                                            if (!field.ReadOnlyField && field.InternalName != "Attachments" &&      field.InternalName  != "TaxCatchAll")   
                                            {
                                                if (agendaPointItem[field.Id] != null)
                                                {
                                                    string targetFieldInternalName = field.InternalName;
                                                    if (listItem.Fields.ContainsField(field.InternalName))
                                                    {
                                                        listItem[targetFieldInternalName] = agendaPointItem[field.InternalName];
                                                    }
                                                }
                                            }
                                        }

                                        string reasonreturned = "---- <br/>Reason returned: " + currentSite.Title + " Rejected. " + "<br/> "
                                                                         + agendaPointItem.GetTaxonomyFieldValueByLanguage(site, MeetingsCommon.Constants.FIELDS_AGENDAPOINTDECISION_NAME, 1036) + "<br/> "
                                                                         + agendaPointItem.GetTaxonomyFieldValueByLanguage(site, MeetingsCommon.Constants.FIELDS_AGENDAPOINTDECISION_NAME, 1043) + "<br/> "
                                                                         + agendaPointItem.GetFieldValue(MeetingsCommon.Constants.FIELDS_AGENDAPOINTDECISIONCOMMENTSNL_NAME)
                                                                         + agendaPointItem.GetFieldValue(MeetingsCommon.Constants.FIELDS_AGENDAPOINTDECISIONCOMMENTSFR_NAME)
                                                                         + agendaPointItem[MeetingsCommon.Constants.FIELDS_AGENDAPOINTSREASONRETURNED_NAME] + "<br/>----";

                                        SPFieldUrlValue value = new SPFieldUrlValue();
                                        value.Description = currentSite.Title;
                                        value.Url = currentSite.Url;                                      
                                        listItem[MeetingsCommon.Constants.FIELDS_AGENDAPOINTPOSTPONEDFROM_NAME] = value;
                                        listItem[MeetingsCommon.Constants.FIELDS_MEETING_NAME] = null;
                                        listItem[MeetingsCommon.Constants.FIELDS_AGENDAPOINTSTATUS_NAME] = null;
                                        listItem[MeetingsCommon.Constants.FIELDS_AGENDAPOINTSREASONRETURNED_NAME] = reasonreturned;

                                        //Clear the category and status field
                                        listItem.ClearTaxonomyFieldValue(MeetingsCommon.Constants.FIELDS_AGENDAPOINTSTATUS_NAME);
                                        listItem.ClearTaxonomyFieldValue(MeetingsCommon.Constants.FIELDS_AGENDAPOINTDECISION_NAME);
                                        listItem.SystemUpdate(false);
                                    }                                           
                                }
                            }
                        }
                    });
                }
            }
            catch (Exception ex)
            {

                throw;
            }

        }
4

1 に答える 1

5

次のようにして修正しました

 DocumentSet docSetCreated = DocumentSet.Create(targetList.RootFolder, agendaPointItem.Name, targetCTId, new Hashtable(), true);
                                        int  listItemId = docSetCreated.Item.ID;
                                        SPListItem listItem = targetList.GetItemById(listItemId);

どうやらドキュメントセットが作成された後、そのオブジェクトのリストアイテムを使用できなくなったので、新しいオブジェクトを取得する必要があります

于 2012-10-02T12:43:45.630 に答える