0

Is there a way to change a SharePoint Image site column to enable the use of RichText, and then propagate that change across all sites of the site collection?

The issue I am experiencing is that content exists in an Image site column that was previously lacking RichText enabled (see https://stackoverflow.com/a/12320373/791932).

Previously:

<Field ID="{26a21730-d4b3-426b-8837-c65590fad99c}"
Type="Image"
Name="HeadlineImage"
DisplayName="Headline Image"
Group="Publishing Site Columns" />

Now:

<Field ID="{26a21730-d4b3-426b-8837-c65590fad99c}"
Type="Image"
Name="HeadlineImage"
DisplayName="Headline Image"
Group="Publishing Site Columns"
RichText="TRUE"
RichTextMode="FullHtml" />

Markup:

<PublishingWebControls:RichImageField
ID="HeadlineImage"
runat="server"
FieldName="HeadlineImage" />

Site columns and content types are deployed entirely by features, and no customization of the columns or types is done through the SharePoint UI.

After deploying this change and propagating (using the gl-propagatecontenttype extension and checked through SharePoint Manager 2010), when returning to the page to edit the content of the column, it is still rendered as text-based HTML (as described in https://stackoverflow.com/q/3815053/791932).

I'd like to find a method to do this by destroying as little content as possible; if it's possible to avoid dropping the site collection or deleting sites and re-provisioning, that would be ideal.

1 Answer 1

0

The issue turned out to be that the fields of the pages themselves were not updated in the propagation step. By writing a quick console app, I was able to update them manually:

private const string BannerImageSchema = @"<Field ID=""{f13d37b8-63c0-44a7-927b-c911df08df7b}"" Type=""Image"" Name=""BannerImage"" DisplayName=""Banner Image"" Group=""Publishing Site Columns"" Format=""Image"" RichText=""TRUE"" RichTextMode=""FullHtml"" />";

public static void Main()
{
    using (SPSite sitecollection = new SPSite("http://SPSite"))
    {
        using (SPWeb root = sitecollection.RootWeb)
        {
            var pagesList = root.Lists["Pages"];
            foreach (SPListItem item in pagesList.Items)
            {
                RetypeFields(item);
            }
        }

        foreach (SPWeb web in sitecollection.AllWebs)
        {
            try
            {
                var pagesList = web.Lists["Pages"];
                foreach (SPListItem item in pagesList.Items)
                {
                    RetypeFields(item);
                }
            }
            finally
            {
                if (web != null) web.Dispose();
            }
        }
    }

    Console.WriteLine("Done");
    Console.ReadKey();
}

private static void RetypeFields(SPListItem item)
{
    Console.WriteLine(string.Format("Updating {0}", item.Title));

    try
    {
        var bannerImageField = item.Fields[new Guid("{f13d37b8-63c0-44a7-927b-c911df08df7b}")];
        bannerImageField.SchemaXml = BannerImageSchema;
        bannerImageField.Update();
    }
    catch (Exception ex)
    {
        Console.WriteLine(string.Format("Couldn't update item {0}: {1}", item.Title, ex.Message));
    }
}

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.