Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Programmatically moving Document Set not keeping Lookup Field Values

$
0
0

Hi,

I have a Document Library that uses a Content Type which is based on a DocumentSet Content Type.

I added a couple of Lookup Fields and all working fine.

Then tried to programmatically move the DocumentSet to another Document Library that also has the same Custom Content Type added to it. So both Document Libraries are identical except for their name.

The move works perfectly and brings over all the values entered - except it doesn't keep the existing values that were selected in the Lookup Fields of the original Document Set.

The code I used is (almost identical) below - taken from the website: http://social.msdn.microsoft.com/Forums/en-US/1e8b1110-a719-4825-a300-cc1946f4d96a/document-sets-move-programatically?forum=sharepointdevelopmentprevious

                using(SPSite site =newSPSite("http://amr-laptop"))//Get the site
               
{
                   
using(SPWeb web= site.RootWeb)//Get the web
                   
{
                       
SPList list = web.Lists["My documents"];//Get the list
                       
SPFolder folder = list.RootFolder;//Find the folder to create in
                       
SPContentType docsetCT = list.ContentTypes["Document Set"];//Find the content type to use
                       
Hashtable properties =newHashtable();//Create the properties hashtable
                        properties
.Add("DocumentSetDescription","New Document Set");//Populate the properties
                       
foreach(SPListItem itemin list.Items)
                       
{
                           
if(item.Folder!=null)
                           
{
                               
DocumentSet newDocset =DocumentSet.GetDocumentSet(item.Folder);
                               
if(newDocset !=null)
                               
{
                                   
//Now we'll export it so we can create an exact copy of it somewhere else
                                   
byte[] compressedFile = newDocset.Export();
                                   
//Then we get the target list
                                   
SPList targetList = web.Lists["NewDocumentLib"];
                                   
SPContentType secondCt = targetList.ContentTypes["Document Set"];
                                   
SPFolder targetFolder = targetList.RootFolder;
                                   
DocumentSet.Import(compressedFile, item.Name+"Backup", targetFolder, secondCt.Id, properties, web.CurrentUser);
                               
}
                           
}
                       
}
                   
                   
}
               
}

Any ideas on how I can keep the Lookup values in the resulting Document Set after it has been moved.

Thanks,

Grant.


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>