views:

310

answers:

1

Hi

Is it possible to programmatically change a "multi-line text field" to "single-line text field" ?

SPFieldMultiLineText field = list.Fields["sample"] as SPFieldMultiLineText;
// how to change the type to 'single line' now ?

Or do I need to create an additional field (with a similiar name) and migrate the content?

Thanks for any help.

+1  A: 

You can change a Note (MultiLineText) field into a Text (SingleLineText) field under certain restrictions.

  • The Note must be in Plain Text format. Rich formatting and FullHtml will not work, and you will receive a non-supported field type change error.
  • If the Note already has a value in it, you should not try this if that text has over 255 characters. This is because the value of the field is retained when you change the type from Note to Text.

The code is simply as follows. You don't even need to specify that it is MultiLine.

SPField field = list.Fields["sample"];
field.Type = SPFieldType.Text;
field.Update();
ccomet
Thanks a lot, I'll try it.
driAn