找传奇、传世资源到传世资源站!

Syndication实现读取、创建、订阅、更新Rss例子 附完整源码下载

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

该实例主要目的是了解Syndication,并实现了如下功能                                                           一、了解RSS源
     二、RSS源格式
     三、如何创建RSS源
     四、如何订阅RSS源     五、如何更新RSS源
该项目需要引用引用System.ServiceModel.Web 命名空间         
using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.ServiceModel.Syndication;using System.ServiceModel.Web;using System.Xml;using System.Collections.Generic;/// <summary>/// 此页面主要用作浏览RSS的条目/// </summary>public partial class LookRss : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { ReadRss(); } /// <summary> /// 读取RSS内容 /// </summary> private void ReadRss() { //TextSyndicationContent Rss20FeedFormatter feed = new Rss20FeedFormatter(); //1、得到RSS源路径 string sRssString = GetFullyQualifiedUrl("rss.xml"); //2、读取RSS中的内容 using (XmlReader xreader = XmlReader.Create(sRssString)) { feed.ReadFrom(xreader); } lblTitle.Text = feed.Feed.Title.Text; if (feed.Feed.Copyright != null) { lblCopyright.Text = feed.Feed.Copyright.Text; } //3、显示RSS中的内容 repeater1.DataSource = feed.Feed.Items; repeater1.DataBind(); } /// <summary> /// 得到虚拟目录地址(与本程序无关) /// </summary> /// <param name="url"></param> /// <returns></returns> private string GetFullyQualifiedUrl(string url) { string sUrl1 = Request.Url.GetLeftPart(UriPartial.Authority); string sUrl2 = ResolveUrl(url); return string.Concat(Request.Url.GetLeftPart(UriPartial.Authority), ResolveUrl(url)); }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复