copy list items from one list to another in sharepoint

前端 未结 11 2051
无人共我
无人共我 2020-12-14 20:35

In Sharepoint how can you copy a list item from one list to another list eg copy from \"List A\" to \"List B\" (both are at the root of the site)

I want this copying

11条回答
  •  北海茫月
    2020-12-14 20:41

    private void CopyAttachmentsToList(SPListItem srcItem, SPListItem tgtItem)
    {
        try
        {
            //get source item attachments from the folder
            SPFolder srcAttachmentsFolder =
                srcItem.Web.Folders["Lists"].SubFolders[srcItem.ParentList.Title].SubFolders["Attachments"].SubFolders[srcItem.ID.ToString()];
    
            //Add items to the target item
            foreach (SPFile file in srcAttachmentsFolder.Files)
            {
                byte[] binFile = file.OpenBinary();
                tgtItem.Update();
                tgtItem.Attachments.AddNow(file.Name, binFile);
                tgtItem.Update();
            }
        }
        catch
        {
            //exception message goes here
        }
        finally
        {
            srcItem.Web.Dispose();
        }
    }
    

    Don't forget to add this line, tgtItem.Update();, else you will get an err.

提交回复
热议问题