Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » Samples » Downloads
 
Add your own
alternative version

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

, 18 Feb 2005
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

About the Author

Dariush Tasdighi
Web Developer
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
I'm experienced in below items:
 
- XML 1.0
- CSS 2.0
- ASP 3.0
- HTML 4.01
- XHTML 1.0
- Javascript 1.5
- .NET Framework 1.1/2.0
- Microsoft Office 2000/XP
- Microsoft Visual Basic 6
- Microsoft SQL Server 2000/2005
- Microsoft C#.NET (Windows Based)
- Microsoft C#.NET (XML Web Service)
- Microsoft C#.NET (Web Based = ASP.NET)
 
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

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 18 Feb 2005
Article Copyright 2005 by Dariush Tasdighi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid