0

We've developed a custom Sharepoint feature with custom site column and custom content type. We have no problems in production environment, but we're facing a problem in next development steps and releases: when there's the need to add a new Site column to an existing content type, I cannot manage to propagate the changes to the subsites. I see the new column in the root site, I see the content type in the root site with the new column, but in the lists in the subsites using that content type I always see the content type without the new column. No idea what to do here: the only thing that work is adding manually the column to the content type for each list using it: time consuming, and the column is added for EVERY content type in the list, not only the custom one.

Please advice

Thanks Alessandro

1

1 Answer 1

0

I've found a method to check for the content type available link fields and update it in all subsites, matching the one in the root site.

Hope it helps

foreach (SPWeb web in site.AllWebs)
{
    System.Console.WriteLine("Processing web {0}",web.Url);
    try
    {
        //Gets page list
        SPList page = web.Lists.TryGetList(Constants.ListName.News);
        SPFieldCollection webFields = web.Fields;
        SPContentType webContentType = page.ContentTypes[Constants.ContentType.NewsCTName];

        if (webContentType != null)
        {
            foreach (SPField field in rootContentType.Fields)
            {
                if (!webContentType.Fields.ContainsField(field.InternalName))
                {
                    SPFieldLink link = new SPFieldLink(field);
                    webContentType.FieldLinks.Add(link);
                    webContentType.Update();

                    System.Console.ForegroundColor = ConsoleColor.Green;
                    System.Console.WriteLine("Added {0} to {1}", field.InternalName, web.Url);
                    System.Console.ResetColor();
                }
            }
        }

        web.Dispose();
    }
    catch (Exception ex)
    {
        System.Console.ForegroundColor = ConsoleColor.Red;
        System.Console.WriteLine(ex.Message);
        System.Console.WriteLine(ex.StackTrace);
        System.Console.ResetColor();
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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