文件*已由SHAREPOINT \ system修改

时间:2012-10-02 12:14:56

标签: c# sharepoint sharepoint-2010

在当前场景中,我试图将文档集从一个库复制到另一个库,事情是我无法使用DocumentSet.Import,因为我只需要docset属性而不是内容。

此代码的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;
            }

        }

1 个答案:

答案 0 :(得分:5)

我修了它,做了以下

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

显然在创建文档集之后,我不能再使用该对象的listitem,我需要获得一个新的