I am trying to add a new column to a contentytpe and type note but with rich text enabled.
It doesnt throw any exceptions: In the site columns definition it appears as Multiple lines of text with rich text enabled.
However when I place the cursor inside the field, the ribbon is not chaning to show the bold,italic, etc.
the code is as follows:
using (SPSite spsite = new SPSite(strurl))
{
using (SPWeb currentWeb = spsite.OpenWeb())
{
try
{
currentWeb.AllowUnsafeUpdates = true;
SPContentType agendaPointsProposedCT = currentWeb.ContentTypes[Meetings.Common.Constants.CONTENTTYPES_AGENDAPOINTPROPOSED_NAME];
string reasonReturnedFieldName = currentWeb.Fields.Add(Meetings.Common.Constants.FIELDS_AGENDAPOINTSREASONRETURNED_NAME, SPFieldType.Note, false);
SPFieldMultiLineText reasonReturnedField = currentWeb.Fields.GetFieldByInternalName(reasonReturnedFieldName) as SPFieldMultiLineText;
reasonReturnedField.Group = "$Resources:XXX,Field_XXXColumns_Group";
string schemaXmlWithResourceTokens = reasonReturnedField.SchemaXmlWithResourceTokens;
string displaynamelocalized = "$Resources:XXX,Field_ReasonReturned_Name";
string returnValue;
int indexOfAttributeName = schemaXmlWithResourceTokens.IndexOf("DisplayName", StringComparison.InvariantCultureIgnoreCase);
int indexOfAttibuteValueBegin = schemaXmlWithResourceTokens.IndexOf('"', indexOfAttributeName);
int indexOfAttributeValueEnd = schemaXmlWithResourceTokens.IndexOf('"', indexOfAttibuteValueBegin + 1);
returnValue = schemaXmlWithResourceTokens.Substring(0, indexOfAttibuteValueBegin + 1) + displaynamelocalized + schemaXmlWithResourceTokens.Substring(indexOfAttributeValueEnd);
reasonReturnedField.SchemaXml = returnValue;
reasonReturnedField.RichText = true;
reasonReturnedField.RichTextMode = SPRichTextMode.FullHtml;
reasonReturnedField.AllowHyperlink = true;
reasonReturnedField.Update(true);
agendaPointsProposedCT.AddFieldRefFromContentType(currentWeb, reasonReturnedField, true);
MoveFieldInColumnOrderToLastPosition(currentWeb, Meetings.Common.Constants.CONTENTTYPES_AGENDAPOINTPROPOSED_NAME, reasonReturnedField.InternalName);
public static void AddFieldRefFromContentType(this SPContentType contentType, SPWeb web,SPField field, bool pushChanges)
{
SPFieldLink fieldLink = new SPFieldLink(web.AvailableFields.GetField(field.InternalName));
//Check if the Field reference exists
if (!contentType.Fields.ContainsField(field.Title))
{
contentType.FieldLinks.Add(fieldLink);
contentType.Update(pushChanges);
}
else
{
//Do Nothing
}
}
