banita
banita

Reputation: 143

how to show rss feed in c# window application

i want to know can we make application in c# donet in which we can show rss feed directly in a form or can we make widgets . And for every update there should be notification to user.although iam showing rss feed by just showing the web page of rss feed.

Upvotes: 1

Views: 1767

Answers (2)

Edwin Tai
Edwin Tai

Reputation: 1334

here is my code for my blog you can visit here

  public XmlDocument GetRss(int count)
    {
        XmlDocument xml=new XmlDocument();
        XmlElement root,chn,elm;
        xml.AppendChild(xml.CreateXmlDeclaration("1.0", "utf-8", "yes"));
        root = xml.CreateElement("rss");
        root.SetAttribute("version", "2.0");
        xml.AppendChild(root);

        chn = xml.CreateElement("channel");
        root.AppendChild(chn);

        elm = xml.CreateElement("title");
        elm.InnerText = System.Web.Configuration.WebConfigurationManager.AppSettings["sitename"];
        chn.AppendChild(elm);

        elm = xml.CreateElement("link");
        elm.InnerText = System.Web.Configuration.WebConfigurationManager.AppSettings["host"];
        chn.AppendChild(elm);

        elm = xml.CreateElement("description");
        elm.InnerText = System.Web.Configuration.WebConfigurationManager.AppSettings["sitedes"] ;
        chn.AppendChild(elm);


        List<Blog> blogs = BlogManager.Instance.GetBlogLists(count);
        foreach (Blog bg in blogs)
        {
            Blog blog=BlogManager.Instance.ReadBlog(bg.keyword,bg.path);
            if (blog.encryption.Trim() == string.Empty)
            {
                XmlElement item = xml.CreateElement("item");
                chn.AppendChild(item);
                elm = xml.CreateElement("title");
                item.AppendChild(elm);
                elm.InnerText = blog.title;

                elm = xml.CreateElement("pubDate");
                item.AppendChild(elm);
                elm.InnerText = blog.pubdate.ToString("r");

                elm = xml.CreateElement("link");
                item.AppendChild(elm);
                elm.InnerText = System.Web.Configuration.WebConfigurationManager.AppSettings["host"] + "Blog/"+bg.path+"/" + blog.keyword + ".esp";

                elm = xml.CreateElement("description");
                item.AppendChild(elm);
                elm.AppendChild(xml.CreateCDataSection(blog.description));

                elm = xml.CreateElement("guid");
                item.AppendChild(elm);
                elm.InnerText = System.Web.Configuration.WebConfigurationManager.AppSettings["host"] + "Blog/" + bg.path + "/" + blog.keyword + ".esp";
                elm.SetAttribute("isPermaLink", "false");
            }

        }
        return xml;

    }

you can set it into a IHttpHandler form

using System; using System.Web; using Edwin.Web; using Edwin.Object; using System.Collections.Generic; public class Rss : IHttpHandler {

public void ProcessRequest (HttpContext context) {
    if (context.Request.RawUrl.ToLower().Trim().IndexOf(".ashx") != -1) context.Response.Redirect(context.Request.RawUrl.Replace(".ashx", ".esp"));
    context.Response.AddHeader("Cache-Control", "no-cache");
    context.Response.ContentType = "text/xml; charset=utf-8";
    Edwin.Web.BlogManager.Instance.GetRss(20).Save(context.Response.OutputStream);

}

public bool IsReusable {
    get {
        return false;
    }
}

}

Upvotes: 0

Lloyd Powell
Lloyd Powell

Reputation: 18820

Create a timer that will check the RSS at regular intervals, if the latest items "pubDate" isn't the same as the last item you received, then all of the items that are of a later date/time of the most recent item you received will require a notification.

Upvotes: 1

Related Questions