在当前场景中,我试图将文档集从一个库复制到另一个库,问题是我不能使用 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;
}
}