Click here to Skip to main content
12,406,971 members (60,040 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » Samples » Downloads

Stats

39.2K views
627 downloads
52 bookmarked
Posted

A very standard, powerful and easy to use Sample and Library for working on RSS 2.0

, 18 Feb 2005 MIT
With this library, you can easily create some RSS 2.0 files for your site and/or use some RSS 2.0 files from other sites into your site.
namespace working_on_rss
{
	public class display_rss2_samples : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.DataGrid grdData;
		protected System.Web.UI.WebControls.DropDownList cboSamples;

		#region Web Form Designer generated code
		override protected void OnInit(System.EventArgs e)
		{
			InitializeComponent();
			base.OnInit(e);
		}

		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
			this.grdData.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(grdData_ItemDataBound);

		}
		#endregion

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!(Page.IsPostBack))
				Initialize();

			string strPathName = "";

			switch(cboSamples.SelectedIndex)
			{
				case 0:
					strPathName = Server.MapPath("rss") + "\\RSS2Sample1.xml";
					grdData.DataSource = IranianExperts.RSS.RSSUtilities.GetRSSFeed(IranianExperts.RSS.RSSLocation.Drive, strPathName, IranianExperts.RSS.RSSFeedType.item);
					grdData.DataBind();
					break;

				case 1:
					strPathName = Server.MapPath("rss") + "\\RSS2Sample2.xml";
					grdData.DataSource = IranianExperts.RSS.RSSUtilities.GetRSSFeed(IranianExperts.RSS.RSSLocation.Drive, strPathName, IranianExperts.RSS.RSSFeedType.item);
					grdData.DataBind();
					break;

				case 2:
					strPathName = "http://localhost/working_on_rss/rss/RSS2Sample1.xml";
					grdData.DataSource = IranianExperts.RSS.RSSUtilities.GetRSSFeed(IranianExperts.RSS.RSSLocation.URL, strPathName, IranianExperts.RSS.RSSFeedType.item);
					grdData.DataBind();
					break;

				case 3:
					strPathName = "http://localhost/working_on_rss/rss/RSS2Sample2.xml";
					grdData.DataSource = IranianExperts.RSS.RSSUtilities.GetRSSFeed(IranianExperts.RSS.RSSLocation.URL, strPathName, IranianExperts.RSS.RSSFeedType.item);
					grdData.DataBind();
					break;

				case 4:
					strPathName = "http://localhost/working_on_rss/create_rss2_sample1.aspx";
					grdData.DataSource = IranianExperts.RSS.RSSUtilities.GetRSSFeed(IranianExperts.RSS.RSSLocation.URL, strPathName, IranianExperts.RSS.RSSFeedType.item);
					grdData.DataBind();
					break;

				case 5:
					strPathName = "http://localhost/working_on_rss/create_rss2_sample2.aspx";
					grdData.DataSource = IranianExperts.RSS.RSSUtilities.GetRSSFeed(IranianExperts.RSS.RSSLocation.URL, strPathName, IranianExperts.RSS.RSSFeedType.item);
					grdData.DataBind();
					break;
			}
		}

		private void Initialize()
		{
			cboSamples.Items.Clear();

			cboSamples.Items.Add("Display RSS2 Sample (1) File From Local Drive");
			cboSamples.Items.Add("Display RSS2 Sample (2) File From Local Drive");
			cboSamples.Items.Add("Display RSS2 Sample (1) File From URL");
			cboSamples.Items.Add("Display RSS2 Sample (2) File From URL");
			cboSamples.Items.Add("Display Dynamic (.ASPX File) RSS2 Sample (1) File From URL");
			cboSamples.Items.Add("Display Dynamic (.ASPX File) RSS2 Sample (2) File From URL");

			cboSamples.AutoPostBack = true;
		}

		private void grdData_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			switch(e.Item.ItemType)
			{
				case System.Web.UI.WebControls.ListItemType.Item:
				case System.Web.UI.WebControls.ListItemType.SelectedItem:
				case System.Web.UI.WebControls.ListItemType.AlternatingItem:
					System.Data.DataRowView oDataRowView = (System.Data.DataRowView) e.Item.DataItem;

					string strLINK = oDataRowView["LINK"].ToString();
					string strTITLE = oDataRowView["TITLE"].ToString();

					int intTitleMaxLenght = 20;

					if(strLINK == "")
					{
						if(strTITLE.Length <= intTitleMaxLenght)
							e.Item.Cells[0].Text = strTITLE;
						else
							e.Item.Cells[0].Text = strTITLE.Substring(0, intTitleMaxLenght - 1) + " ...";
					}
					else
					{
						if(strTITLE.Length <= intTitleMaxLenght)
							e.Item.Cells[0].Text = "<a href='" + strLINK + "' target='_blank'>" + strTITLE + "</a>";
						else
							e.Item.Cells[0].Text = "<a href='" + strLINK + "' target='_blank'>" + strTITLE.Substring(0, intTitleMaxLenght - 1) + " ...</a>";
					}

					break;
			}
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License

Share

About the Author

Dariush Tasdighi
Web Developer Sematec Ins.
Iran (Islamic Republic of) Iran (Islamic Republic of)
My experiences are:

HTML 5.0, CSS 3.0
JQuery, Angular JS, Bootstrap

MVC 5.0, WEB API, c#

My Site URLs:
http://www.IranianExperts.ir
http://www.IranianExperts.com

My Yahoo Group URL: http://groups.yahoo.com/group/iranianexperts

Mobile: 0098-912-108-7461
Address: Tehran, Tehran, Iran

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160730.1 | Last Updated 18 Feb 2005
Article Copyright 2005 by Dariush Tasdighi
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid