0

I want to change a column type from multiline text to HTML.

I tried this:

string urlRoot = ConfigurationManager.AppSettings["url"].ToString();
SPSite site = new SPSite(urlRoot);
SPList list = site.RootWeb.Lists["Agenda"];
HtmlField htmlField = new HtmlField(list.Fields, "HTML", "NewHTMLField");
SPField fieldInContentType = list.ContentTypes["Agenda"].Fields["Body Intro"];
fieldInContentType = htmlField;
fieldInContentType.Update();

But I got the following exception:

Value does not fall within the expected range

Is it possible to do this?

1 Answer 1

1

All you have to do is change the RichTextMode property for the existing multi-line text field as follows:

using (SPSite site = new SPSite("http://sharepointdev:9000"))
{
    SPList list = site.RootWeb.Lists.TryGetList("List1");
    SPFieldMultiLineText fld = list.Fields["MultiText1"] as SPFieldMultiLineText;
    fld.RichText = true;
    fld.RichTextMode = SPRichTextMode.FullHtml;
    fld.Update(true);
}

Should do the trick.

Your Answer

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