在Web站点中创建和使用Rss源(二)
//页面后台代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = GetDataSet();
Rss rss = new Rss();
rss.OutputStream = Response.OutputStream;
rss.RssTitle = "DotNetBips.com Latest Articles";
rss.PublisherUrl = Request.Url.Host;
rss.Description = "DotNetBips.com - Applying .NET";
rss.Copyright = "Copyright (C) DotNetBips.com.";
rss.Generator = "DotNetBips.com RSS Generator";
rss.ItemSource = ds;
rss.ItemTitleField = "Title";
rss.ItemDescriptionField = "Description";
rss.ItemPublicationDateField = "Pubdate";
rss.ItemUrlField = "Url";
rss.ItemAuthor = "Author";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "text/xml";
Rss.PublishRss(rss);
Response.End();
}
public DataSet GetDataSet()
{
string connString = "Server=. ; DataBase=News ; uid=sa ; pwd=coser";
SqlConnection conn = new SqlConnection(connString);
string sql = "select * from Article ";
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
sda.Fill(ds, "Article");
return ds;
}
}
作者Sweet Life
补充:Web开发 , 其他 ,