0
votes

I have created two custom lists And able to copy list item from one list to other using work flows in sharepoint designer 2010.but my requirement is to copy all the items in one list to another using work flow. I have searched for the same on google , I didnt find the correct solution, Can any one suggest an Idea for the same?

Thanks in advance.

1

1 Answers

1
votes

You should create a new custom workflow activity to do this . Here is a sample code to do this . For more information about create a new workflow activity check this link : http://msmvps.com/blogs/sundar_narasiman/archive/2010/12/26/develop-custom-workflow-activity-for-sharepoint-2010-workflow.aspx

    private void ProcessActivity(ISharePointService service)
    {
        using (SPWeb web = (SPWeb)(SPContext.Current.Web))
        {             
            SPList sourceList = web.Lists[sourceListid];                   
            SPListItemCollection ic = sourceList.Items;
            foreach (SPItem i in ic)
            {
                SPListItem item = sourceList.Items.GetItemById(Convert.ToInt32(i.["ID"].ToString()));                 
                CopyItems(item,DestinationListName);
            }
        }

    }

    private SPListItem CopyItems(SPListItem sourceItem, string destinationListName)
    {
        //Copy sourceItem to destinationList
        SPList destinationList = sourceItem.Web.Lists[destinationListName];
        SPListItem targetItem = destinationList.Items.Add();
        foreach (SPField f in sourceItem.Fields)
        {
            //Copy all except attachments.
            if (!f.ReadOnlyField && f.InternalName != "Attachments"
                && null != sourceItem[f.InternalName])
            {
                targetItem[f.InternalName] = sourceItem[f.InternalName];
            }
        }

        targetItem.Update();

        return targetItem;
    }

Good luck.