Using C # to generate RSS

Source: Internet
Author: User
Tags cdata comments tostring
Rss

<%@ 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>
Get aggregated articles
</summary>
public class RSS:System.Web.UI.Page
{
Components.genrss gr = new Components.genrss (); Instantiating an Object

String strrss = "";

private void Page_Load (object sender, System.EventArgs e)
{
Response.ContentType = "Application/xml"; Output and displayed as XML data
Response.Write (Getrss ());
}

<summary>
Get aggregated articles
</summary>
public string Getrss ()
{
DataSet ds = gr. Generaterss (); Call the Generaterss () method to get the data

Strrss = Strrss + "<rss version=\" 2.0\ ">";
Strrss = Strrss + "<channel>";
Strrss = Strrss + "<title> natives manufacturing </title>";
Strrss = Strrss + "<link>http://www.socent.com</link>";
Strrss = Strrss + "<description> natives manufacturing </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> natives manufacturing </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;
}

Code generated #region the Web forms Designer
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}

<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
This. Load + = new System.EventHandler (this. Page_Load);
}
#endregion
}
}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.