Friday, August 8, 2014

Copy a Field’s Value to another Field in SharePoint


public static void CopyFieldValues(string siteURL,String copyFromFieldInternalName,String copyToFieldInternalName)
        {
            using (SPSite site = new SPSite(siteURL))
            {
                foreach (SPWeb web in site.AllWebs)
                {
                    //Get all the ListItems in every list of the web that has the 2 fields
                    var items = (from l in web.Lists.Cast<SPList>()
                                 where l.Fields.ContainsField(copyFromFieldInternalName)
                                     && l.Fields.ContainsField(copyToFieldInternalName)
                                 from i in l.Items.Cast<SPListItem>()
                                 select i).ToList();

                    //For each listitem in this web, migrate the content of the old one to the new one
                    //To do this, we use the tranformation Func that was given as a parameter

                    foreach (SPListItem item in items)
                    {
                        Console.WriteLine("WebUrl: "+web.Url + "ListName: "+ item.ParentList.Title);
                       
                        item[copyToFieldInternalName] = item[copyFromFieldInternalName];
                        //Do system update to avoid modifying the item's version
                        item.SystemUpdate(false);
                    }
                }
            }
        }

        

No comments:

Post a Comment

Image noise comparison methods

 1. using reference image technique     - peak_signal_noise_ratio (PSNR)     - SSI 2. non-reference image technique     - BRISQUE python pac...