如何在c#窗口应用程序中显示RSS源

问题描述:

我想知道我们可以在c#donet中创建应用程序,其中我们可以直接在窗体中显示RSS源或可以创建窗口小部件。并且对于每一个更新应该有通知给用户。虽然iam通过显示RSS源的网页来显示RSS源。如何在c#窗口应用程序中显示RSS源

创建一个计时器,该计时器将定期检查RSS,如果最近的项目“pubDate”与您收到的最后一个项目不一样,那么所有的项目的日期/时间您收到的最近的项目将需要通知。

+0

但我怎么能检查包含RSS订阅页面的内容。我如何存储内容 – banita 2009-07-23 07:47:25

这里是我为我的博客代码 您可以访问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; 

    } 

你可以设置成使用系统的IHttpHandler形式

; using System.Web; 使用Edwin.Web;使用Edwin.Object的 ; using System.Collections.Generic; 公共类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; 
    } 
} 

}