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 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
            }
        }
share|improve this question
    
I found this, social.technet.microsoft.com/Forums/en/…, but I am getting the field after adding it, so no sure how to implement the solution here –  L.V. Sharepoint Architect Sep 14 '12 at 14:45
    
I'd be curious to see what the line:contentType.Fields.ContainsField(field.Title)) returns. –  Derek Gusoff Sep 14 '12 at 17:32
    
...because if it returns false your update code never gets hit –  Derek Gusoff Sep 14 '12 at 17:34
    
it gets hit, the field is in the list. –  L.V. Sharepoint Architect Sep 14 '12 at 18:52
add comment

1 Answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.