Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
add comment

migrated from stackoverflow.com Jul 24 '11 at 11:44

This question came from our site for professional and enthusiast programmers.

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.