0

I am trying to add Site column(already created site column) to a document library but getting the following error : "A duplicate field name "b8581e64-01d1-4bef-9af9-06d190583664" was found."

Below is the code snippet:

 public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            using (SPSite site = new SPSite("http://localhost:32155/sites/Test/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    try
                    {
                        if (web.IsRootWeb)
                        {
                            SPListCollection docLibraryColl = web.GetListsOfType(SPBaseType.DocumentLibrary);
                            foreach (SPList list in docLibraryColl)
                            {
                                if (!list.Fields.ContainsField("Archivered Status"))
                                {
                                    list.Fields.Add(web.AvailableFields["Archivered Status"]);
                                    list.Update();
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        string msg = ex.Message;
                    }
                }
            }
        }

Can someone help me to find why am i getting this error?

0

The field already exists in the list. It's possible that the same field is added to the list but with a different name. 80% chance that this is the cause of your error.

You can use 'containsfieldwithstaticname' to check if a field exists by using the internal name of a field. https://msdn.microsoft.com/EN-US/library/microsoft.sharepoint.spfieldcollection.containsfieldwithstaticname.aspx

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.