The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Brand your CS Feeds with the RSS 2.0 image Tag

0 replies.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a flat view of this topic  Flat View
Previous Topic   Next Topic
Threaded View: This topic has 0 replies on 1 page
Brendan Tompkins

Posts: 158
Nickname: brendant
Registered: Apr, 2005

Brendan Tompkins is .NET Developer and founder of CodeBetter.Com
Brand your CS Feeds with the RSS 2.0 image Tag Posted: Apr 13, 2005 11:03 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Brendan Tompkins.
Original Post: Brand your CS Feeds with the RSS 2.0 image Tag
Feed Title: Brendan Tompkins
Feed URL: /error.htm?aspxerrorpath=/blogs/brendan.tompkins/Rss.aspx
Feed Description: Blog First. Ask Questions Later.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Brendan Tompkins
Latest Posts From Brendan Tompkins

If you subscribe to a CodeBetter.Com blog with Bloglines, for example, you may have noticed that we’ve added an RSS 2.0 image tag to our feeds.

This involved just a few lines of code, all added to Community Server’s $\Components\Syndication\BaseRssWriter.cs class. Here's the step-by-step if you want to do it yourself.

Step 1: Add an AddImageElement Method.

Add this code somewhere in the BaseRssWriter class:

    /// <summary>

    /// ADDs the image element.

    /// </summary>

    /// <param name="link">Link.</param>

    /// <param name="description">Description.</param>

    protected void AddImageElement(string link, string description)

    {

      // Image Example

      //<image>

      //  <title>Joel On Software</title>

      //  <url>http://www.joelonsoftware.com/RssJoelOnSoftware.jpg</url>

      //  <link>http://www.joelonsoftware.com</link>

      //  <width>144</width>

      //  <height>25</height>

      //  <description>Painless Software Management</description>

      //</image>

      this.WriteStartElement("image");

      this.WriteElementString("title",Title);

      this.WriteElementString("url", BaseUrl + "/RSS2Image.gif");

      this.WriteElementString("link", FormatUrl(link));

      this.WriteElementString("width", "144");

      this.WriteElementString("height", "25");

      this.WriteElementString("description", description);

 

      this.WriteEndElement();

    }

Step 2: Add Calling Code to the BuildChannel Method.

Add the bolded statement below after the “generator” element in the BuildChannel method.

    protected void BuildChannel(string link, string description, string lang)

    {

      this.WriteElementString("title", Title);     

      this.WriteElementString("link", FormatUrl(link));

      this.WriteElementString("description", description);

      this.WriteElementString("dc:language", lang);

      this.WriteElementString("generator", SiteStatistics.CommunityServerVersionVersionInfo);

 

      this.AddImageElement(link, description);

    }

Step 3 Create your RSS Image:

Create a 144 x 25 pixel gif image, and place it in the root of your Community Server Site.

Okay, if you’ve looked at the code above and thought to yourself, “What if my image is a different size?” or “What if I want a different image for each blog?” or “What if I want to use a JPEG or PNG image instead?” 

Well, then you’ve got some code to write!  For now, this was a quick fix, and I only wanted to add one image to all feeds so I didn’t make it configurable.  You should be able to add these as configuration properties, but this will involve additional coding.  If you only want one image for all feeds, my code will work fine for you.

That’s it! 

-Brendan

Read: Brand your CS Feeds with the RSS 2.0 image Tag


Topic: Code worst Previous Topic   Next Topic Topic: Multiple overloads with distinguishing parameter as object is dangerous

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use