4

I am trying to render html tags with text in RichHtmlField control in SharePoint. Following is html code.

 <%@ Register TagPrefix="Publishing" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<Publishing:EditModePanel ID="pnlDisplay" runat="server" PageDisplayMode="Display" SuppressTag="true">
     <Publishing:RichHtmlField ID="RichHtmlField2" FieldName="eNetContactInformation" ControlMode="Display" runat="server" />
</Publishing:EditModePanel>
<Publishing:EditModePanel ID="pnlEditPanel" runat="server" PageDisplayMode="Edit" SuppressTag="false">
     <Publishing:RichHtmlField ID="RichHtmlField1" FieldName="eNetContactInformation" ControlMode="Edit" runat="server" />
</Publishing:EditModePanel>

My site column (site collection level) schema definition is:

<Field
    ID="{24056b49-f914-4935-a304-8cc2d1a01f0b}"
    Name="eNetContactInformation"
    DisplayName="Contact Information"
    Type="HTML"
    RichText="True"
    RichTextMode="FullHTML"
    Required="FALSE"
    Group="eNet"
   >
  </Field>

I also tried following script to update site column of "pages" list for given sub site.

$site = get-spsite -limit All | where-object {$_.Url -eq "http://intra.******.enet"}



Write-Host "Vishal Processing Site Collection:" $site.Url
     foreach($web in $site.AllWebs)
   {
      Write-Host "Web:" $web.Url
       if($web.Url -like "http://intra.*****.enet/about/regions")
       {
         $list = $web.Lists["Pages"]
         [Microsoft.SharePoint.Publishing.Fields.HtmlField]$field =   [Microsoft.SharePoint.Publishing.Fields.HtmlField]$list.Fields.GetFieldByInternalName("eNetContactInformation")
         $field.RichText = $true
         $field.RichTextMode = [Microsoft.SharePoint.SPRichTextMode]::FullHtml
         Write-Host "Field: " $field.Title
         $field.Update()
         Write-Host "List: " $list
         $list.Update()
        }
    }

After too many efforts, still RichHtmlField control showing text as HTML markup.

Output:

enter image description here

Background:

We have big list of data ( with markup tags values) on production. Contact Information field have values containing HTML markup tags. In production it is working fine. It is properly rendering HTML. Great!

Now, the issue is in development and UAT environment. We had some strange thing going on which causes RichHTMLField control to display markup tags. RichHTMLField control referring Site Level Column. Publishing Feature is activated on site collection level and SharePoint Server Publishing feature is activated on web level. We do everything through VS2012 (No SP Designer). We can not afford to delete site column.

Do we missed any settings? or do we over-right any settings / binding with site columns?

2
  • That may sound strange, but when I had these kind of issues with rendering data from richhtmlfields I did not hesitate to use a html encoder/decoder, an existing one or wrote one myself. I learned not always search for a 100% SharePoint solution but use code snippets to save time.
    – user20451
    Dec 11, 2013 at 14:17
  • I followed below links: link 1 link 2 Dec 12, 2013 at 6:52

1 Answer 1

2

Sorry for replying with answer after long time. I wondered when I saw there is no answer to this question. So decided to do self-reply to this question. After lots of brain storming I get to know there was silly mistake I did in feature receiver. When I debug application I come to know that I was getting null values from site column properties. Then I placed null check condition on site column property values.

 public override void FeatureActivated(SPFeatureReceiverProperties properties)
            {
               List<string> htmlFields = new List<string> { "LunchBody","ContactInformation", "RegionsField", "SummaryLinksTools",
                        "OperatingSystemList" };

               if (properties != null)
                    {
                        SPSite currentSite = properties.Feature.Parent as SPSite;
                        SPWeb rootWeb = currentSite.RootWeb;
                        //Update site column in site collection
                        UpdateSiteColumns(htmlFields, rootWeb);

                        foreach (SPWeb childWeb in currentSite.AllWebs)
                        {
                            try
                            {
                                //Update pages library for each site.
                                UpdatePagesList("eNetContactInformation", childWeb);
                            }
                            finally
                            {
                                if (childWeb != null)
                                    childWeb.Dispose();
                            }
                        }

                    }
        }

private static void UpdateSiteColumns(List<string> htmlFields, SPWeb web)
        {
            foreach (string fieldName in htmlFields)
            {
                UpdateSiteColumn(web, fieldName);
                web.Update();
            }
        }

private static void UpdateSiteColumn(SPWeb web, string fieldName)
        {
            SPFieldMultiLineText fld = (SPFieldMultiLineText)web.Fields.GetFieldByInternalName(fieldName);
            string richTextValue = fld.GetProperty("RichText");
            if (!string.IsNullOrEmpty(richTextValue))
                fld.RichText = true;

            string richTextMode = fld.GetProperty("RichTextMode");
            if (!string.IsNullOrEmpty(richTextMode))
                fld.RichTextMode = SPRichTextMode.FullHtml;

            fld.PushChangesToLists = true;
            fld.Update(true);
        }

So this way we can update the site level columns through VS code.

However we can do same thing with the script as mentioned in question itself. It was running successfully but I was checking with wrong SharePoint site. Below powershell script is ok.

$site = get-spsite -limit All | where-object {$_.Url -eq "http://intra.******.enet"}



Write-Host "Vishal Processing Site Collection:" $site.Url
     foreach($web in $site.AllWebs)
   {
      Write-Host "Web:" $web.Url
       if($web.Url -like "http://intra.*****.enet/about/regions")
       {
         $list = $web.Lists["Pages"]
         [Microsoft.SharePoint.Publishing.Fields.HtmlField]$field =   [Microsoft.SharePoint.Publishing.Fields.HtmlField]$list.Fields.GetFieldByInternalName("eNetContactInformation")
         $field.RichText = $true
         $field.RichTextMode = [Microsoft.SharePoint.SPRichTextMode]::FullHtml
         Write-Host "Field: " $field.Title
         $field.Update()
         Write-Host "List: " $list
         $list.Update()
        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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