This is a migrated thread and some comments may be shown as answers.

Problem: content is stripped when saving to PublishingPageContent Field

12 Answers 214 Views
WebParts for SharePoint
This is a migrated thread and some comments may be shown as answers.
Torsten Hufsky
Top achievements
Rank 1
Torsten Hufsky asked on 30 Jul 2009, 07:07 PM
Hi,

I'am trying to create a Publishing Page with HTML content inside.
The Web in what i try to create the page has both radEditor features(RadEditorFeatureRichHtml and RadEditorFeatureRichText) activated.

My code looks like that.
PublishingPage currentPage = ......; 
SPFile spFile = currentPage.ListItem.File; 
SPListItem fileItem = spFile.Item; 
fileItem[FieldId.PublishingPageContent] = htmlContent; 
newFileItem.Update(); 

 The Html content starts for example with that:
<table class ="testClass" cellspacing="0" cellpadding="0" border="0"

After the update() method is called the saved output looks like
<table class =testClass cellspacing=0 cellpadding=0 border=0


Also comments like
<!-- comment -->
are stripped.

I've discovered serveral ways to get the content into the field. I even put the content through filestream into the
field but sharepoint always strips the characters.I also tried to Encode the content but this also not worked.

If I call the RadEditor through the graphical interface and set the EditModes to HTML and then paste my html code it works fine and the content is saved in the correct form. I thought if your editor is able to save html content without stripping, there must be a way to save it through the api.

Please tell me if there are any possibilities to save the content through the API.


Thanks and greets Torsten

12 Answers, 1 is accepted

Sort by
0
Stanimir
Telerik team
answered on 31 Jul 2009, 06:04 AM
Hello Torsten,

You can use the following static methods.
1. Telerik.SharePoint.EditorTools.UnEscapeSpecialTags(string html) - this will encode the content before saving it.
2. Telerik.SharePoint.EditorTools.EscapeSpecialTags(string html) - this will decode the content before displaying it.

I hope this helps.

Best wishes,
Stanimir
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Torsten Hufsky
Top achievements
Rank 1
answered on 31 Jul 2009, 06:47 AM
Hello Stanimir,

thanks for your reply.
I will try your solution. But for displaying the content i have to write a
control adapter and decode the writer stream. Is this right?

Best wishes,
Torsten
0
Torsten Hufsky
Top achievements
Rank 1
answered on 31 Jul 2009, 08:29 AM
Ok i tried this methods but with no success.

The fixed Html string is the same as given into the methods. I think because the
method searches for tags like object|script|embed|iframe but the double quotes after class it ignores.


0
Torsten Hufsky
Top achievements
Rank 1
answered on 31 Jul 2009, 12:16 PM
Sorry for flooding with replies :)

Now i have changed the Regex pattern to 
string tagsToReplace = "object|script|embed|iframe|img" 
and now it encodes also the img tags.

The main problem here is also the sharepoint content filter because it deletes your tag id=\"RadEditorEncodedTag.
So that i'm not able to decode the string.

what to do?

0
Stanimir
Telerik team
answered on 04 Aug 2009, 01:18 PM
Hello Torsten,

If you want to disable the ContentFilters of the RadEditor for MOSS you will need to modify the respective ConfigFile.xml or ListConfigFile.xml. Just add the following line.
<property name="ContentFilters">None</property> 

You can disable a certain filters by setting the ContentFilters to use only the filters that you like to be executed. For example if you want to disable the RemoveScripts filter, you will need to add the following code.
<property name="ContentFilters">MakeUrlsAbsolute,FixUlBoldItalic,FixEnclosingP,IECleanAnchors,MozEmStrong,ConvertFontToSpan,ConvertToXhtml,IndentHTMLContent</property>  


You can find more information on the ContentFilters in the following help article http://www.telerik.com/help/aspnet-ajax/contentfilters.html.

One other thing you can do is checking what content is sent to the server. You can do this by using a debugging tool such as fiddler. If you see that you send the correct content, then the problem is caused by the MOSS content filter. When you submit the page, MOSS will validate it and automatically make changes if the content is not valid. You can verify this by trying to enter the same content with the original SharePoint rich text editor.


Regards,
Stanimir
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Alan Coulter
Top achievements
Rank 1
answered on 12 Nov 2009, 12:31 PM

I am currently building an Internet site using MOSS WCM and Telerik. I have the control rendering correctly, which is bound to a rich HTML field. If I switch to code view and paste the following HTML:

<div class="module gray">  
            <h2>Quick Links</h2> 
            <ul> 
                <li><a href="#" class="translate">Translations</a></li>  
                <li><a href="#" class="donate">Donate</a></li>  
                <li><a href="#" class="cmmi">CMMI</a></li>  
                <li><a href="#" class="pathology">StV Pathology</a></li>  
            </ul> 
            </div> 
            <div class="module gray">  
            <h2>Maps &amp; Facilities</h2> 
            <ul> 
                <li><a href="#" class="maps">Maps</a></li>  
                <li><a href="#" class="parking">Parking</a></li>  
                <li><a href="#" class="transport">Public Transport</a></li>  
                <li><a href="#" class="clock">Visiting hours</a></li>  
            </ul> 
            </div> 
 
Then click the Design tab and switch back to the HTML tab, the HTML is changed. E.g. All of the double quotes around the internal class elements have been removed. The divs are also converted to uppercase, along with things like the h2 tag. So now my W3C site is none compliant. Can someone tell me how I fix this? I've heard rumours that it actually SharePoint manipulating the HTML when the HTML is being bound to the field value.
0
Torsten Hufsky
Top achievements
Rank 1
answered on 12 Nov 2009, 02:23 PM
Thank you for your answer Alan.
I know this way of editing html content. My problem was, that i wanted to import some html content from a xml file into
sharepoint programatically.

Meanwhile i solved the problem. I described the problem in our blog.

Sharepoint XSS Filter on Communardo Techblog


0
Alan Coulter
Top achievements
Rank 1
answered on 12 Nov 2009, 08:44 PM
Hi Torsten,
Unfortunately my German is non-existent and can't understand your blog. Is it just a xml compliance setting somewhere that I am missing? If you could elaborate in English I would really appreciate it. Thanks.
0
Stanimir
Telerik team
answered on 13 Nov 2009, 07:52 AM
Hello Alan,

You can use the google translate functionality to view the page in English.
http://translate.google.com/translate_t

Regards,
Stanimir
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Alan Coulter
Top achievements
Rank 1
answered on 19 Nov 2009, 10:22 PM
Hi,

Your article talks about programmatically migrating content into SharePoint. You discuss 3 options, all of which as you say failed in some way. Then the final solution section says:

"To the content but as required to be able to import 1:1, now had to find a workaround. This offered an encoding of the import complained HTML tags. Following the successful integration of the methods in our import all content can now be taken as required".

This makes no sense to me. Did you encode the content?  Anyway, my problem is actually using the Telerik rad editor. As I said, I have the XHTML compliance setting set. Then if I switch to HTML mode and paste in the XHTML, after toggling between the Design and HTML tabs, the HTML is changed.  Also, if I use the control to insert an image with a class, what I see is XHTML compliant code. In this case, switching back and forth between Design and HTML makes no changes to the HTML (which is what I want). Yet, once I check in the page and look at the code, not only is the image tag no longer XHTML compliant, but the class that I specified has lost its double quotes.  E.g.
<img class=blue alt="Here is a news article photo" src="/res/images/news/news01.jpg"

Do I need to build a control adapter or something? Which control do I need to intercept?
0
Torsten Hufsky
Top achievements
Rank 1
answered on 23 Nov 2009, 08:35 AM
I know this problem. The sharepoint xss filter kills any (ok some) xhtml compliant characters like the double quote you mentioned. I described this in my blog.

You can use the ARF toolkit by SPWorks. Use the CompatibilityPanel around your Rad Editor to correct the mistakes done by sharepoint.
But be carefull. The ARF Framework has some bugs.
0
Alan Coulter
Top achievements
Rank 1
answered on 24 Nov 2009, 01:27 AM
Hi Torsten,

I had a look at ARF, but I gave up trying to work through the code to identify the key methods to call. What I have done now is incorporated a slightly modified version of the MIL.Html code sample on CodeProject. This has a very easy to understand stub program that demonstrates how to interact with it.  I initially created a Control adapter for the control type of Microsoft.SharePoint.WebControls.RichTextField. Although this works in modifying the underlying HTML rendered by SharePoint, it affects the Reusable content pages. My thoughts now are to modify the control adapter to intercept the Microsoft.SharePoint.Publishing.WebControls.RichHtmlField and write override code for the RenderFieldForDisplay method.  Does this sound OK to you?  Or were you just thinking about wrapping the telerik:RadHtmlField in another web control that just manipulate its contents?
Tags
WebParts for SharePoint
Asked by
Torsten Hufsky
Top achievements
Rank 1
Answers by
Stanimir
Telerik team
Torsten Hufsky
Top achievements
Rank 1
Alan Coulter
Top achievements
Rank 1
Share this question
or