Fix: Content Editor Web Part Rich Text Editor Popup fails to display


 

Introduction

This problem has been bugging me for the past 3 days and so I thought I’d be kind and document it just in case it has been causing someone else problems.

So the issue is with the SharePoint 2007 Content Editor Web Part and when you edit the web part and click the button to show the Rich Text Editor you get a JavaScript error.

There does seem to be another post on MSDN (http://social.msdn.microsoft.com/Forums/en-NZ/sharepointcustomization/thread/90e14ff3-7003-44fd-9b4c-d9e654f7d8e1 that was showing the same issue and although the fix was related, the fixes that were specified in this post didn’t help me.

 

Issue

So as I have already mentioned when using the SharePoint 2007 Content Editor Web Part’s Rich Text Editor Dialog you get the following JavaScript error:-

Invalid Argument in HtmlEditor.js at line 5740, character position 2

On further investigation it is this line in the HtmlEditor.js file that is causing the problem.

elem=document.getElementByid(containerId);

Actually if you follow the JavaScript code then the issue seems to be down to the piece of JavaScript where the web parts are registered on the page. At the bottom of each SharePoint page is a section of JavaScript that looks something like this:-

 1: <script LANGUAGE='Javascript'>


 

 2: <!--


 

 3: WPSC.Init(document);


 

 4: var varPartWPQ1 = WPSC.WebPartPage.Parts.Register('WPQ1','[GUID]',document.all.item('WebPartWPQ1'));


 

 5: WPSC.WebPartPage.WebURL = 'http:\u002f\u002fsharepointurl';


 

 6: WPSC.WebPartPage.WebServerRelativeURL = '\u002f';


 

 7: //-->


 

 8: </script>

It seems that the JavaScript which creates the varPartWPQ1 variable does not work properly as the varPartWPQ1 is created without populating its ID property. This ID property is the value that is assigned to containerId in the line:-

elem=document.getElementByid(containerId);

 

The Solution

After a lot of trial and error I found that it was to do with the master page and a <meta> tag within the master page’s <head> tag.

The tag causing the problem is this one:-

 1: <meta http-equiv="X-UA-Compatible" content="IE=8" />

Removing this line and redeploying the master page fixed the JavaScript error.

This meta tag tells IE to run in IE 8 Standards mode which seems to cause a problem with the browser when its trying to get a document item using the function document.all.item([itemid]).

For more information on the <meta> tag please see the following article on Defining Document Compatability (http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx)

 

Further Information

The reason for this happening was actually that the master page was being ported back from a SharePoint 2010 master page to a SharePoint 2007 master page.

This tag was left in from the SharePoint 2010 master page.

I really do hope this helps someone as it drove me mad for a while.

SharePoint Utility to manage Content Type and List Event Receivers


Introduction

Recently I have been building a solution which makes use of Content Type Event Receivers. The event receivers were being deployed using declarative xml for example:-

<ContentType ID=”[Removed]” Name=”My Content Type” Group=”My Content Types” Version=”0″>
<DocumentTemplate TargetName=”/_layouts/CreatePage.aspx” />
<XmlDocuments>
<XmlDocument NamespaceURI=”http://schemas.microsoft.com/sharepoint/events“>
<Receivers xmlns:spe=”http://schemas.microsoft.com/sharepoint/events“>
<Receiver>
<Name>MyEventHandler</Name>
<Type>ItemUpdated</Type>
<SequenceNumber>10000</SequenceNumber>
<Assembly>MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=000000000000</Assembly>
<Class>MyAssembly.EventReceivers.ContentTypeEventReceiver</Class>
<Data></Data>
<Filter></Filter>
</Receiver>
……

Now this normally works great, except when you make a mistake. Its quite well known that upgrading Content Types that have been defined using declarative xml can be tricky.

This is one of the reasons why Microsoft released Feature Upgrades in SharePoint 2010 (if you haven’t seen this then please check out Chris O’Brien’s set of blog posts (http://www.sharepointnutsandbolts.com/2010/06/feature-upgrade-part-1-fundamentals.html) on the subject).

In this case the development was on a SharePoint 2007 environment and I found myself in a situation with deploying Content Type Event Receivers.

It seems that once the Content Type had been deployed and the feature switched on its quite difficult to make certain changes to the content type. This includes changes like the following:-

  • changing a field’s default value
  • changing whether a field is required
  • changing the event receiver definition
    However, unfortunately Gary LaPointe’s stsadm commands would not working correctly for my content type and Gaetan Bouveret’s utility only manages list event receivers but does look very good at that!

Solution

Therefore I started to write my own command line utility. The first version was quickly written to get what I needed to do, done.

I have updated it so that at least its a bit more intuitive but it still only allows you to modify event receivers at a content type or list level.

Please be careful because if you ask it to delete an event receiver then guess what it will delete the event receiver!

As with all these utilities please do not try using this on your production environment without performing some testing on a development environment beforehand.

If you have any comments, problems with the utility please leave a comment and I’ll take a look..

Utility System Requirements:-

  • SharePoint 2007 SP2 (Tested on April 2010 and April 2011 Cumulative Update)
  • Utility must be run from machine which is connected to the SharePoint farm that is being modified.

Usage:-

Console application name: ITSP.EventReceiverConfig.exe

Command Line Arguments:-

  • -url : full url of site that hosts content type or list
  • -mode : [list | add | remove]
  • -targettype : [list | contenttype | assembly]
  • -targetname : [name of list | name of content type | name of assembly]
  • -assembly : [full assembly name including version number etc]
  • -class : [fully qualified class name that is implementing the event receiver]
  • -type : [itemadding | itemadded | itemupdating | itemupdated]
  • -sequence : [number bigger than 1]

The utility with releases, document and source code can be found on Codeplex.

Codeplex Project: http://itspeventreceiver.codeplex.com

Documentation can be found here: http://itspeventreceiver.codeplex.com/documentation