Bart's Smarts

Smart .NET, Silverlight, and SharePoint Development.

Archive for the ‘SharePoint’ Category

Customize the Text Editors in SharePoint 2007

Posted by sapientcoder on February 3, 2009

If you’re like me, you probably aren’t a huge fan of the text editors that ship with SharePoint 2007. Aside from known browser compatibility issues, they aren’t all that great from a usability standpoint either. I figured this out fairly early on when I was training our users on how to author content in SharePoint.

Take, for example, the “insert hyperlink” button that appears in the editor toolbar. I noticed that in some places it button would bring up a nice “browse” dialog that lets the user easily select a link target. In other places, I’d get a stripped down dialog box with two fields: Text to Display and Address. In this second case, I’d have the daunting task of trying to explain to non-technical users how to copy-and-paste URLs to documents and other targets into this dialog. Not great from a usability design perspective.

If you’re thinking of trying to customize the built-in editors to make them more usable or cross-browser, I’d recommend against it (at least until the process hopefully becomes easier). I started down this path and was soon dismayed to find that fixing the text editors involves modifying or overriding core JavaScript files in the 12 hive.

Furthermore, customizing the built-in text editors involves customizing multiple controls. On the one hand, SharePoint uses an HTML editor control for Content Editor Web Parts and for Web Content Management (authoring/editing pages). On the other hand, it uses a Rich Text editor control for rich text (and enhanced rich text) fields in lists.

(Note: If you want to specifically customize the HTML text editor in SharePoint without worrying about the Rich Text editor, you can modify the RTE2ToolbarExtension.xml file that’s stored in the Editing Menu folder of the Master Page gallery. This allows at least some level of customization without modifying core JS files.)

So instead of trying to customize the editors that ship with SharePoint, I recommend replacing them. Specifcally, I recommend using the free RadEditor control from Telerik (a company who works closely with Microsoft). It’s an ASP.NET control that renders a textarea with an editing toolbar, similar to how the built-in editors are rendered. The difference, though, is that it’s cross-browser, more usable, and easier to customize. Also, it gives you the option to use the nice “browse” dialogs (called Asset Picker Dialogs) built into SharePoint or use the cross-browser dialogs designed by Telerik.

Here are the steps to get it installed on your server farm:

  1. Install ASP.NET AJAX Extensions 1.0 on all web front-end servers in the farm.
  2. Download the RadEditor control from Telerik.
  3. Install it (can be done globally or on a per-web application basis).

Note that the RadEditor installation instructions (#3 above) differ slightly for WSS and MOSS. The documentation contains links to both sets of instructions.

The next step is to tell SharePoint where to use it (use any or all of these links, depending where you want it used):

  1. Using RadEditor in List Items
  2. Using RadEditor Web Part (in place of the Content Editor Web Part)
  3. Using RadEditor for Web Content Management (Page Authoring/Editing)

Lastly, you have two dialog choices for the “Insert Hyperlink” and “Insert Image” buttons on the RadEditor toolbar. The first choice is to use the cross-browser dialogs designed by Telerik. The second is to use the Asset Picker Dialogs built into SharePoint. You may want to examine the trade-offs before you decide.

If you decide to go with the Asset Picker Dialogs built into SharePoint, read Telerik’s instructions that talk about which config files to modify. To swap out the dialogs, go to each applicable config file, and look for the tools named ImageManager and LinkManager. To use the Asset Pickers, simply add MOSS (all caps) to the front of the tool names (e.g. MOSSImageManager). Note that this will only work in MOSS, not WSS (because the Asset Pickers aren’t included as part of WSS).

And that’s it. For information about how to further customize the toolbar (add/remove buttons, add new CSS styles, etc.),  see the RadEditor documentation.

Posted in SharePoint | Tagged: , | Leave a Comment »

“Unable to Display this Web Part” Error in MOSS 2007

Posted by sapientcoder on November 14, 2008

If you’ve worked with SharePoint (MOSS) 2007 for any length of time, you’ve probably seen this error by now:

Unable to display this web part. To troubleshoot the problem, open this page…

I won’t bother typing out the rest of it because what it says, like most SharePoint error messages, isn’t incredibly helpful anyway.

There are many things that can cause this error (like doing a site restore with SharePoint Designer, etc.), but I’m writing about a specific circumstance I encountered today.

I had a case today where I saw this error on ALL web parts on a page simultaneously. Now, if they had all been web parts hooked into RSS feeds or web services or something, then maybe it wouldn’t have surprised me as much that they all failed at once (perhaps because of a network problem or something). However, these were web parts like a Summary Link Web Part and a couple of Content Query Web Parts.

Upon turning on debugging in Web.config, I discovered that the problem was my ItemStyle.xsl file (in the Style Library) that’s used by the Content Query Web Parts. An XSL template that I had copied-and-pasted from a blog into the file had a slight syntax error in it (it had “<br/>” as “</br>”).

So, the moral of the story is that syntax errors in your ItemStyle.xsl file can cause all web parts on a page to fail if any of the web parts are making use of that file. It would be nice if SharePoint would give a slightly better error message (like “Problems with the item styles used by this page prevent it from being displayed correctly” or something along those lines), but that’s not the case.

Posted in SharePoint | Tagged: , , | Leave a Comment »

Andertoons Daily Cartoon in SharePoint

Posted by sapientcoder on August 25, 2008

If you haven’t seen the cartoons at www.andertoons.com, I highly recommend you check them out when you get a chance. They’re friendly, non-offensive cartoons (at least the ones I’ve seen are) that are good for using in corporate environments such as on company intranets.

I stumbled upon Andertoons because I was looking for a way to increase traffic to the Information Technology site within our corporate intranet, and I decided (after some research) that posting a daily technology cartoon might be an easy way to drum up a little more interest in the site. I wanted something funny but a little less controversial than Dilbert.

Since our corporate intranet is built on SharePoint (MOSS) 2007, I initially decided to use the “RSS Viewer” web part in SharePoint to hook into the daily technology cartoon feed from Andertoons. At first, everything appeared to be fine… until I went to look at the site the day after and discovered that the cartoon hadn’t updated in SharePoint although it was clearly updated when I typed the feed’s URL in my browser and pulled it up that way.

After many hours of research and troubleshooting, I discovered that some RSS feeds don’t return the correct data when the Http request made to the feed doesn’t include a “User Agent” string in the request. The behavior when this happens can differ from one feed to the next but is usually along the lines of no data returned, “stale” (cached) data returned, etc. As it turns out, SharePoint’s RSS viewer leaves that field empty when requesting RSS feeds (see this discussion thread on MSDN).

The fix? Well, there are a couple of options. The first option is to ask the site hosting the RSS feed to change their processing logic so that an empty “User Agent” field returns correct data. The other option is to use a different method to request the feed so that the “User Agent” field isn’t empty. In my case, I used Visual Studio .NET 2005 to create a custom web part that goes out, grabs the feed, pulls the latest cartoon image from it, and renders the image. The key is that I manually set the “User Agent” field in my web request.

Without getting into all of the details of creating custom web parts, the majority of the code inside of my CreateChildControls method looks like this:

using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.Web;
// plus the normal SharePoint web part namespaces

public override void CreateChildControls()
{
    ...

    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(FEED_URL);

    // manually set the "User Agent" field so the current (non-cached) feed is returned;
    // it really doesn't matter what the value is just so long as it's not blank
    request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";

    WebResponse response = request.GetResponse();

    string html;
    using (StreamReader reader = new StreamReader(response.GetResponseStream())
    {
        html = HttpUtility.HtmlEncode(reader.ReadToEnd());
        Match m = Regex.Match(html, @"www\.andertoons\.com\/cartoon\/(\d+)");

        if (m.Success)
        {
            html = "&amp;lt;br /&amp;gt;&amp;lt;img border=0 src=\"http://www.andertoons.com/img/cartoons/" +
                match.Groups[1].Value + ".jpg" + "\"&amp;gt;";
        }
    }

    if (html != null)
    {
        // output the contents of "html"
    }

    ...
}

Posted in SharePoint | Tagged: , , | 1 Comment »