当前位置: 移动技术网 > IT编程>开发语言>.net > 建立自己的RSS

建立自己的RSS

2018年04月29日  | 移动技术网IT编程  | 我要评论

杨龙写,台湾嘟嘟论坛,楚雄彝族自治州区号

本文主要提供代码,创建自己的rss,供别人订阅...

--- rss.aspx

<%@ page language="c#" codebehind="rss.aspx.cs" autoeventwireup="false" inherits="socent.rss" %>

--- rss.aspx.cs

using system;
using system.collections;
using system.componentmodel;
using system.data;
using system.drawing;
using system.web;
using system.web.sessionstate;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.htmlcontrols;

namespace socent
{
 /// <summary>
 ///  取得聚合文章
 /// </summary>
 public class rss : system.web.ui.page
 {
  components.genrss gr = new components.genrss(); // 实例化对象

  string strrss = "";

  private void page_load(object sender, system.eventargs e)
  {
   response.contenttype = "application/xml"; // 输出并按xml数据显示
   response.write (getrss());
  }

  /// <summary>
  /// 取得聚合文章
  /// </summary>
  public string getrss()
  {  
   dataset ds = gr.generaterss(); // 调用generaterss()方法,获得数据

   strrss = strrss + "<rss version=\"2.0\">";
   strrss = strrss + "<channel>";
   strrss = strrss + "<title>土人制造</title>";
   strrss = strrss + "<link>http://www.socent.com</link>";
   strrss = strrss + "<description>土人制造</description>";
   for(int i = 0; i < ds.tables[0].rows.count; i++)
   {
    strrss = strrss + "<item>";
    strrss = strrss + "<title><![cdata["+ds.tables[0].rows[i]["title"]+"]]></title>";
    strrss = strrss + "<link>http://www.socent.com/articleshow@"+ds.tables[0].rows[i]["id"]+".html</link> ";
    strrss = strrss + "<description><![cdata["+ds.tables[0].rows[i]["description"]+"]]></description>";
    strrss = strrss + "<copyright>土人制造</copyright>";
    strrss = strrss + "<pubdate>"+convert.todatetime(ds.tables[0].rows[i]["adddate"].tostring()).tostring("yyyy-mm-dd hh:mm")+"</pubdate>";
    strrss = strrss + "<comments>http://www.socent.com/commentshow@"+ds.tables[0].rows[i]["id"]+".html</comments>";
    strrss = strrss + "</item>";
   }
   strrss = strrss + "</channel>";
   strrss = strrss + "</rss>";

   return strrss;
  }

  #region web 窗体设计器生成的代码
  override protected void oninit(eventargs e)
  {
   //
   // codegen: 该调用是 asp.net web 窗体设计器所必需的。
   //
   initializecomponent();
   base.oninit(e);
  }

  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void initializecomponent()
  {   
   this.load += new system.eventhandler(this.page_load);
  }
  #endregion
 }
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网