question

SLM-5683 avatar image
0 Votes"
SLM-5683 asked AllenXu-MSFT commented

Best way to convert a SP 2013 (w/attachments) to Document Sets?

What is the best way to convert a SP 2013 (w/attachments) to Document Sets?

I need to convert a SharePoint 2013 list (that has attachments) to a Document Library with Document Sets. I do not have access to SharePoint Designer and I have limited site permissions (one of the perks of working for the government - sigh).

I'm only an Intermediate level SP user so I'd need the feedback "dumbed-down" a little bit please. Any assistance would be greatly appreciated... I'm close to giving up!

office-sharepoint-server-administration
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AllenXu-MSFT avatar image
0 Votes"
AllenXu-MSFT answered AllenXu-MSFT commented

Hi @SLM-5683 ,

According to your description, my understanding is that you want to all attachments in a list to be upload those attachments to a document set, right?

Firstly, to download all attachments in a list to a local folder, you can use the below PowerShell commands.

 #Site URL and List Name variables
 $WebURL = "http://xx/"   
 $ListName = "xxx"  
     
 #Local folder to which attachments to be downloaded
 $DownloadPath = "C:\xx"    
     
 #Get the web
 $Web = Get-SPWeb $WebURL
 #Get the Library
 $List = $Web.Lists[$ListName]    
     
 #Loop through each List item
 foreach ($ListItem in $List.Items)
 {   
     #Set path to save attachment
     $DestinationFolder = $DownloadPath         
     
     #Check if folder exists already. If not, create the folder
     if (!(Test-Path -path $DestinationFolder))        
     {            
         New-Item $DestinationFolder -type directory          
     }
       
     #Get all attachments
     $AttachmentsColl = $ListItem.Attachments
     
     #Loop through each attachment
     foreach ($Attachment in $AttachmentsColl)    
     { 
         #Get the attachment File       
         $file = $web.GetFile($listItem.Attachments.UrlPrefix + $Attachment)        
         $bytes = $file.OpenBinary()                
     
         #Save the attachment as a file  
         $FilePath = $DestinationFolder + " \" + $Attachment
         $fs = new-object System.IO.FileStream($FilePath, "OpenOrCreate")
         $fs.Write($bytes, 0 , $bytes.Length)    
         $fs.Close()    
     }
 }

You will find all attachments in the path you set in parameter $DownloadPath after exectuing the code. Then, use IE to access the document set. Click the "open with Explorer" link in the ribbon.
114388-image.png

Select all attachments in the local folder, and then you can upload all attahcments to the document set via a easy drag.
114481-image.png

Not sure which specific permission level you have to the list and the library but I suppose if you can upload/create documents/items in the list/library, you can easily achieve your requirement by above method. Anyway , have a try to this.

----------Updated----------
@SLM-5683,

There is no OOB way to convert list items to a document set with metadatas. You have to wirte your own code. Here is code which will move/migrate SharePoint List Attachments to Document Library with Created and Modified Date for your reference.

 SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite("SiteURL"))
                {
                    SPList docDestination = site.RootWeb.Lists["DocName"];
                    SPFolder fldRoot = site.RootWeb.Folders[docDestination.Title];
                    SPFileCollection flColl = null;
                    SPList lstAttachment = site.RootWeb.Lists["ListName"];
                    foreach (SPListItem lstItem in lstAttachment.Items)
                    {
                        if (lstItem.Attachments != null && lstItem.Attachments.Count > 0)
                        {
                            foreach (String strName in lstItem.Attachments)
                            {
                                flColl = fldRoot.Files;
                                SPListItem listtem = docDestination.Items.Add();
                                SPFile FileCopy = lstItem.ParentList.ParentWeb.GetFile(lstItem.Attachments.UrlPrefix + strName);
    
                                string destFile = flColl.Folder.Url + "/" + FileCopy.Name;
                                byte[] fileData = FileCopy.OpenBinary();
    
                                SPFile flAdded = flColl.Add(destFile, fileData, site.RootWeb.CurrentUser, site.RootWeb.CurrentUser, Convert.ToDateTime(lstItem[SPBuiltInFieldId.Created]), Convert.ToDateTime(lstItem[SPBuiltInFieldId.Modified]));
                                SPListItem item = flAdded.Item;
                                item[SPBuiltInFieldId.Created] = Convert.ToDateTime(lstItem[SPBuiltInFieldId.Created]);
                                item[SPBuiltInFieldId.Modified] = Convert.ToDateTime(lstItem[SPBuiltInFieldId.Modified]);
                                flAdded.Item.Update();
                            }
    
                        }
                    }
                }
            });

If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


image.png (39.9 KiB)
image.png (156.7 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I need the other data in the list to transfer as well.

0 Votes 0 ·

@SLM-5683 ,

There is no OOB way to convert list items to a document set with metadatas. You have to wirte your own code. Take a reference to my answer above and I updated it with a demo code which will move/migrate SharePoint List Attachments to Document Library with Created and Modified Date.

0 Votes 0 ·

@SLM-5683 ,

If you still need any help, feel free to let me know.


If an Answer is helpful, please click "Accept Answer" and upvote it.

0 Votes 0 ·