Ok. Now that we have our form setup, it’s time to jump into some coding. Again, I’m not going into details about how to code or how things work. Instead, I’m just going to show you what you need to make this application work. Besides, this site isn’t intended to teach you how to program. There are millions of other resources that are way better at that. This site is intended to educate you on what you need for internet marketing and SEO.

Anyways, to get started coding, you will need to get to the Code view. You do that by clicking once on your form in the Solution Explorer panel and clicking the “Show Code” button at the top of the panel. This will take you to the meat of the application. To get started with the source code, we need to add some dependencies at the top with our “using” statements. Most of our dependencies are already listed. But, we need to add a dependency reference for “System.IO” and “System.Xml”. If your code is missing the other references shown below, go ahead and add them as well. But, they should already be there by default.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;

After you’ve added the necessary dependencies, it’s time to add a few variables. These variables will be used in several methods in our code, but will only be used within this single form. So, it’s safe to define those variables as “private” or don’t define them at all to have them default as “private”.

private XmlTextReader rssReader;
private XmlDocument rssDoc;
private XmlNode nodeRss;
private XmlNode nodeChannel;
private XmlNode nodeItem;

Now that we have everything setup, it’s time for the real code. Back in the View Designer, double click on the btnRun button. This will add a Click handler for our button where we’ll be adding the code below. Again, I’m not going to jump into details about what exactly the code does. But, you should still try to get a basic understanding of what the code does. There’s not really a whole lot going on. The first thing it does is clears our list of RSS results (txtFeeds) and creates the necessary objects for reading the RSS feed. After that, it iterates through the XML elements of the RSS response and picks out the parts that it needs as it needs them. After that, it creates new ListViewItem objects that contain the title and description of each RSS record and displays that information in the ListView we created earlier.

            lstFeeds.Items.Clear();
            
            rssReader = new XmlTextReader(txtFeed.Text);
            rssDoc = new XmlDocument();
            rssDoc.Load(rssReader);

            for (int i = 0; i < rssDoc.ChildNodes.Count; i++)
            {
                if (rssDoc.ChildNodes[i].Name == "rss")
                {
                    nodeRss = rssDoc.ChildNodes[i];
                }
            }

            for (int i = 0; i < nodeRss.ChildNodes.Count; i++)
            {
                if (nodeRss.ChildNodes[i].Name == "channel")
                {
                    nodeChannel = nodeRss.ChildNodes[i];
                }
            }

            for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)
            {
                if (nodeChannel.ChildNodes[i].Name == "item")
                {
                    nodeItem = nodeChannel.ChildNodes[i];

                    ListViewItem item = new ListViewItem(nodeItem["title"].InnerText);
                    item.SubItems.Add(nodeItem["description"].InnerText);
                    lstFeeds.Items.Add(item);
                }
            }

That’s it. The only thing left to do now is to run the program. Simply copy and paste a link to your RSS feed (example: http://www.prodigyproductionsllc.com/feed) and click the Run button. You can download the entire source code for this project including the pre-compiled app by clicking the following link: Download Source Code.

Pages: 1 2

Related Posts

Tagged with:  

Leave a Reply