views:

77

answers:

2

Hello everyone,

I am using VSTS 2008 + C# + .Net 3.5 + IIS 7.0 + ASP.Net to develop a simple web application. I want to add RSS feature to some of the pages of my web site, so that people could use their popular RSS reader to receive notification of content update.

Any easy way to do this in my development environment? I only need very basic RSS feature.

thanks in advance, George

+4  A: 

I would suggest you to use the new Syndication API that comes with .NET 3.5. Here is an example from a MSDN How to: Create a Basic RSS Feed article:

public class BlogService : IBlog
{
    public Rss20FeedFormatter GetBlog()
    {
        SyndicationFeed feed = new SyndicationFeed("My Blog Feed", "This is a test feed", new Uri("http://SomeURI"));
        feed.Authors.Add(new SyndicationPerson("[email protected]"));
        feed.Categories.Add(new SyndicationCategory("How To Sample Code"));
        feed.Description = new TextSyndicationContent("This is a how to sample that demonstrates how to expose a feed using RSS with WCF");

        SyndicationItem item1 = new SyndicationItem(
            "Item One",
            "This is the content for item one",
            new Uri("http://localhost/Content/One"),
            "ItemOneID",
            DateTime.Now);

        SyndicationItem item2 = new SyndicationItem(
            "Item Two",
            "This is the content for item two",
            new Uri("http://localhost/Content/Two"),
            "ItemTwoID",
            DateTime.Now);

        SyndicationItem item3 = new SyndicationItem(
            "Item Three",
            "This is the content for item three",
            new Uri("http://localhost/Content/three"),
            "ItemThreeID",
            DateTime.Now);

        List<SyndicationItem> items = new List<SyndicationItem>();

        items.Add(item1);
        items.Add(item2);
        items.Add(item3);

        feed.Items = items;

        return new Rss20FeedFormatter(feed);
    }
}
Pavel Nikolov
This solution creates a separate Url for RSS by using WCF. But I want to integrate the RSS feed into my own web site. For exmaple, in current stackoverflow Url, I can press RSS button to consume RSS directly.
George2
In the source code of this page for example you will find the following line `<link rel="alternate" type="application/atom+xml" title="Feed for question 'How to add RSS feature to my web site?'" href="/feeds/question/3635047">`This line enables the RSS button in browsers and in your case you have to put your feed's URI and title like this:`<link rel="alternate" type="application/atom+xml" title="my feed" href="http://example.com/path/to/atom">` if you use atom `<link rel="alternate" type="application/rss+xml" title="my feed" href="http://example.com/path/to/rss">` for rss
Pavel Nikolov
Thanks, your solution works!
George2
+1  A: 

There is an open-source .net class library called RSS.Net. See http://www.rssdotnet.com/

Zafer
This open source library creates the RSS feed format. But I want to integrate the RSS feed into my own web site. For exmaple, in current stackoverflow Url, I can press RSS button to consume RSS directly.
George2
Please look at http://www.rssdotnet.com/documents/code_examples.html.There you can find out how you can easily generate rss feed for your site.
Zafer
Thanks, but how to enable the RSS button in IE browser? For example, when user browse a page of my web site, and the page has related RSS source, then the IE RSS button is enabled automatically to let user subscribe RSS of the page of my web site?
George2
Create a web page, say rss.aspx. And in your code (as stated in the example) set content type to "txt/xml" and write the feed to the output stream. You can find the related code at the bottom of the page at the link I've provided in my previous comment.
Zafer
I am confused. rss.aspx is the aspx web page which is html format. But RSS is XML format. Your sample provided only generates RSS XML, but what I need is to display my web page html content, and enable IE RSS source button toolbar. So that when user clicks the RSS button, the user could subscribe the feed of the html page. Any comments?
George2
rss.aspx will not contain any html code, it will contain just the page directive (<%@ Page Language="C#" AutoEventWireup="true" CodeFile="rss.aspx.cs" Inherits="rss" %>)... In the code-behind file, you'll write the necessary rss generator code. So that you can get a result like that: http://julianhoffman.wordpress.com/feed/
Zafer
Still confused. Let us talk about the example of Stackoverflow link itself (this question's Url html content and RSS feed) => http://stackoverflow.com/questions/3635047/how-to-add-rss-feature-to-my-web-site In this Url, the page has html content which people is using to discuss/comment/edit, and this page also has enabled RSS button to subscribe current page's RSS feed. So, I think we need to develop two things, the html page itself and the RSS XML page, and also enable RSS subcribe button when user browse html page. In your reply, seems I only need to develop one? This is why I am confused.
George2
(continued) appreciate if you could show me a sample about an html page content and related RSS XML feed (static ones are ok). So that I can download to my local IIS server then I can subcribe the RSS XML when I browse the html page. Any refers?
George2
This is the content page: http://stackoverflow.com/questions/3635047/how-to-add-rss-feature-to-my-web-siteThis is rss feed of that page: http://stackoverflow.com/feeds/question/3635047So, you'll need two seperate pages. One for content, the other for the rss content. On the content page, you can put a link to that rss page and browser automatically understands that that's rss content and shows you the related buttons like subscribe,etc...
Zafer
"On the content page, you can put a link to that rss page and browser automatically understands that that's rss content and shows you the related buttons like subscribe" -- interesting. :-)Could you show me a sample about how to add a link in the content page so that IE can show the RSS subcribe button directly?
George2
Look at the bottom of the page. You'll see the question feed link there :).
Zafer
Interesting. I see it. But how to write link like this so that IE could see it and enable RSS Subscribe button? Any simple samples? Stackoverflow is a little bit complex for a newbie in this area like me to learn. :-(
George2