Friday, August 8, 2014

Delete field from the list

In my case I have 2 columns in the list, I want to delete one column from the list if the list contains 2 columns.


public static void DeleteColumn(string siteURL, String copyFromFieldInternalName, String copyToFieldInternalName)
        {
            using (SPSite site = new SPSite(siteURL))
            {
                foreach (SPWeb web in site.AllWebs)
                {
                    //Get all the List 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)
                                 select l).ToList();

                    foreach (SPList list in items)
                    {
                        Console.WriteLine("WebUrl: " + web.Url);
                        Console.WriteLine("Deleteing the column " + copyFromFieldInternalName + "from the list " + list.Title);
                        list.Fields.Delete(copyFromFieldInternalName);
                        list.Update();
                    }
                }
            }
        }

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...