Images Broken When Viewing Windows SharePoint Services RSS Feeds in Outlook

If using Windows Live Writer or Microsoft Word 2007 to create blog posts in Windows SharePoint Services (WSS) 3.0 it appears, at least on our installation of SharePoint, that when you embed new images in the post, the image tags are generated with relative links, e.g. <img src="/Lists/Posts/Attachments/51/image_thumb.png"> . This is fine if you’re viewing the feeds in a web browser as it can resolve the server name for the links from the feed address. But if you’re using Outlook 2007 to subscribe to the feeds, any images you embedded in the post using Live Writer or Word are generated as relative links, Outlook can’t/doesn’t resolve the site name hence the images are broken:


Whose fault this is (Outlook/SharePoint/Live Writer) I don’t know, but fixing it required a bit of coding hackery – I couldn’t find any option in the SharePoint configuration for controlling the generation of RSS.

WSS v3.0’s default RSS generator is a page called ListFeed.aspx that lives in Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12templatelayouts. By default it looks like this:

<%@ Assembly Name="Microsoft.SharePoint.ApplicationPages" %>
<%@ Page Language="C#" Inherits="Microsoft.SharePoint.ApplicationPages.ListFeed" %> 

Clearly all the logic is in Microsoft.SharePoint.ApplicationPages.dll. So to fix this, I backed up this file and added the following code to ListFeed.aspx which basically passes all of the feed content through a filter using HttpResponse.Filter which uses a regular expression to replaces any relative <img src="/blah"> tags with the absolute <img src="http://site/blah">.

<%@ Assembly Name="Microsoft.SharePoint.ApplicationPages" %>
<%@ Page Language="C#" Inherits="Microsoft.SharePoint.ApplicationPages.ListFeed" %>

protected override void OnInit(EventArgs e)
  base.Response.Filter = new RelativePathFilter(base.Response.Filter, this.Request, this.Response);

class RelativePathFilter : System.IO.Stream
  System.IO.Stream _innerStream;
  string _siteUrl;
  Regex _imagesRegex;
  HttpResponse _response;

  public RelativePathFilter(System.IO.Stream innerStream, HttpRequest request, HttpResponse response)
    _innerStream = innerStream;
    _siteUrl = (new Uri(request.Url, HttpRuntime.AppDomainAppVirtualPath)).AbsoluteUri;
    _response = response;

    // Finds rooted images  tag to be split between 2 Write()s
    content = _imagesRegex.Replace(content, @"$1" + _siteUrl);

    byte[] newBuffer = _response.ContentEncoding.GetBytes(content);
    _innerStream.Write(newBuffer, 0, newBuffer.Length);

  public override bool CanRead { get { return _innerStream.CanRead; } }
  public override bool CanSeek { get { return _innerStream.CanSeek; } }
  public override bool CanWrite { get { return _innerStream.CanWrite; } }
  public override void Flush() { _innerStream.Flush(); }
  public override long Length { get { return _innerStream.Length; } }
  public override long Position { get { return _innerStream.Position; } set { _innerStream.Position = value; } }
  public override int Read(byte[] buffer, int offset, int count) { return _innerStream.Read(buffer, offset, count); }
  public override long Seek(long offset, System.IO.SeekOrigin origin) { return _innerStream.Seek(offset, origin); }
  public override void SetLength(long value) { _innerStream.SetLength(value); }

I’m not entirely sure whether hacking around with these files is supported (although it did seem to survive the installation of WSS 3.0 SP1), or if there’s a better way of doing this, so use at your own risk.

Update 22 April 2008: Modified code so that it doesn’t assume the site is at the root of a virtual server.

16 thoughts on “Images Broken When Viewing Windows SharePoint Services RSS Feeds in Outlook

  1. I tried your solution and it just broke my RSS feads. I had to put the origional code back.

    I am having the same problem you saw, and I just have no idea where to go next.

  2. Okay, scratch my last. Text encoding makes all the difference.

    My RSS feed is no longer crashing, but it doesn’t seem to be fixing the image links. I guess this is the right path, ( wish there was a native setting ), so I just need to play with it.

  3. Russ, I think the issue was that my code originally assumed that the SharePoint site was at the root of a server. The updated code *should* do the trick.

  4. Many Thanks for that! Just as a heads-up: ListFeed.aspx is hard-coded within Sharepoint, so the only way to avoid having to modify that file is to set up some URL Rewriting stuff in IIS that turns ListFeed.aspx to somethingelse.aspx.

  5. Hi,
    great solution!
    I’ve adjusted the Regex, so that a regular link will be “absoluted” as well.
    new Regex:
    _imagesRegex = new Regex(@”(<img .*? \s src \s* = \s* [“”‘]?)/|(<a .*? \s href \s* = \s* [“”‘]?)/”, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);


  6. Rene – this Regex is what you’re after I think:

    _imagesRegex = new Regex(@"(< (img|a) .*? \s (src|href) \s* = \s* [""']?)/", ...);

    (You may need to change the curly quotes that WordPress insists on putting in, to normal ones)

  7. Just wanted to share that this appears to happen with normal blog postings as well. I’ve taken a “broken” Word blog posting, copied it into Notepad, made sure the URLs are fully qualified and then created a new blog posting from that Notepad text. The URLs become relative in the RSS feed.

    I’ve even just created a posting that pulls in an image using the SharePoint interface and the RSS feed does the same thing.

    If this isn’t happening to everyone, something that might be a common factor is the installation of the community blog extensions? I haven’t done enough testing to see if a truly out-of-the-box SharePoint behaves in the same way.

  8. This may be out of the topic but maybe you could help me on this.

    I’ve created a webpart through code and I wanted to add/embed it directly on the page. Could you help me on how to do this?

  9. So, what you are all saying in general is that the RSS Listfeed.aspx file is not easily modifiable w/out adding custom funtions, etc.? 🙂

  10. Very good information about breaking the images during modifying the software, I have never see the information like it.I will careful in future concern it.

  11. Hi, good info. Anyone know of a way to post from Word to SharePoint BUT include embedded images as Live Writer does. Live writer is able to post content with images without checking int he imagages. Word seems to lack this. Is there any way to trick Word to post like Live Writer?

  12. Need some help: Anybody else come across the following problem: When blogging to SharePoint from Word, and I edit an existing post, and add a new image. It replaces an existing image on the post (in Photos Library). Its like Word does not realise that there are already images posted. The problem is probably because when Word submits the new image, it still uses the blog post create date as part of the new image filename. Any ideas?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s