1

This seems to be very simple but can't think of how to approach the task. I want to create an exact copy of another custom list. This can be done by creating a template BUT I want as items are added to Custom List A I want the information to be updated in the copy list created automatically. I am thinking this can be done using a workflow but would that mean I have to create a Copy Item action for every column? Can anyone help me?

3
  • I can't think of any reason you would need data multiplication within SharePoint. What do you need this for? :)
    – Gintas K
    Mar 3 '17 at 12:03
  • If you really want to do this, then yes Workflows or by using EventReceivers
    – Shihan
    Mar 3 '17 at 12:20
  • @Gintas K You are probably thinking that views are the way to go and you are right! For audit purposes I want to have Custom List A has the original and the copy as the copy. I hope this makes sense. Thanks for your help Mar 3 '17 at 13:06
1

One solution for this could be to have a daily back up of your list that gets restored to the duplicated list (Using PowerShell).

  1. Create a new subsite to store your duplicated list
  2. Use Export-SPWeb command to take a backup of your main list
  3. Use Import-SPWeb command to restore that list to the duplicated list.

More details on the commands : https://blogs.technet.microsoft.com/fromthefield/2016/07/14/export-spweb-exporting-lists/

https://technet.microsoft.com/en-us/library/ff607613.aspx

0

This should be what you need:

private SPListItem CopyItem(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];
        }
    }
    //Copy attachments
    foreach (string fileName in sourceItem.Attachments) {
        SPFile file = sourceItem.ParentList.ParentWeb.GetFile(sourceItem.Attachments.UrlPrefix + fileName);
        byte[] imageData = file.OpenBinary();
        targetItem.Attachments.Add(fileName, imageData);
    }

    return targetItem;
}

Source

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.