protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            SPList destinationList = null;
            SPFolder destinationFolder = null;

            _executionContext = executionContext;
            _throwException = Convert.ToBoolean(ExceptionChoice);
            _sourceListItem = GetSourceListItem();
            if (_sourceListItem == null) return ActivityExecutionStatus.Closed;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite destinationSite = GetDestinationSite())
                {
                    if (destinationSite == null) return;

                    using (SPWeb destinationWeb = GetDestinationWeb(destinationSite))
                    {
                        if (destinationWeb == null) return;

                        destinationList = GetDestinationList(destinationWeb);
                        if (destinationList == null) return;

                        destinationWeb.AllowUnsafeUpdates = true;

                        destinationFolder = GetDestinationFolder(destinationWeb, destinationList);
                        if (destinationFolder == null || !destinationFolder.Exists) return;

                        SPContentType destinationContentType = GetDestinationContentType(destinationFolder);
                        if (destinationContentType == null) return;

                        SPFolder sourceListItemAttachmentsFolder = GetSourceItemAttachmentFolder();
                        if (sourceListItemAttachmentsFolder == null) return;

                        foreach (SPFile attachedFile in sourceListItemAttachmentsFolder.Files)
                        {
                            SPListItem destDocument = CopyFile(attachedFile, destinationFolder, destinationContentType);
                            //UpdateDestDocumentProperties(destDocument);
                            string[] ignoreFields = new string[] { "Title", "ContentType", "Content Type", "Name" };
                            _sourceListItem.CopyMetadataTo(destDocument, ignoreFields);
                        }

                        destinationWeb.AllowUnsafeUpdates = false;

                        __ActivationProperties.LogToWorkflowHistory(SPWorkflowHistoryEventType.None, __ActivationProperties.Web.CurrentUser, "The attachments have been copied into the " + destinationList.Title, string.Empty);
                    }
                }
            });

            return ActivityExecutionStatus.Closed;
        }
示例#2
0
 public static void CopyMetadataTo(this SPListItem listItem, SPListItem destinationItem, SPContentType destinationCT)
 {
     string[] ignoreFields = { "ContentType", "Content Type", "Name" };
     listItem.CopyMetadataTo(destinationItem, destinationCT, ignoreFields);
 }