2012-10-02 4 views
1

В текущем сценарии я пытаюсь скопировать набор документов из одной библиотеки в другую, я не могу использовать DocumentSet.Import, потому что мне нужны только свойства docset, а не содержание.Файл * был изменен SHAREPOINT system

Исключение выбрано в 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; 
      } 

     } 

ответ

5

Я установил ее, выполнив следующие действия

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

по-видимому, после того, как documentset создается, я не могу использовать ListItem этого объекта больше, мне нужно, чтобы получить новый один

+0

Хорошая находка. была та же проблема, и просто получение предмета снова помогает. Короче даже 'SPListItem listItem = docSetCreated.ParentListGetItemById (docSetCreated.Item.ID);' –

Смежные вопросы