Rss Reader in visual C#express edition

Hi, I am trying to create an RSS reader in Visual C#express. I need to read the RSS feed into a text box when the form loads. I have never used RSS feeds before , All the examples I encountered were done in visual studio, and it seems I can’t use it:

(XmlReader reader = XmlReader.Create(Url)) 

This is what I got so far. It doesn’t work.

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.Net;

namespace WindowsFormsApplication1
{
public partial class Form1: Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
var s = RssReader.Read("http://ph.news.yahoo.com/rss/philippines");
textBox1.Text = s.ToString();
}
public class RssNews
{
public string Title;
public string PublicationDate;
public string Description;
}

public class RssReader
{
public static List Read(string url)
{
var webResponse = WebRequest.Create(url).GetResponse();
if (webResponse == null)
return null;
var ds = new DataSet();< br /> ds.ReadXml(webResponse.GetResponseStream());

var news = (from row in ds.Tables["item"].AsEnumerable()
select new RssNews
{
Title = row.Field("title"),
PublicationDate = row.Field("pubDate"),
Description = row.Field("description")
}).ToList();
return news;
}
}

I don’t know what to do. Please help .

< div class="answer"> Then your code is working as expected because you are returning a list of RSSNews items, but you assign it to the text box in the wrong way. Do textBox1.Text = s.ToString(); will Give System.Collections.Generic.List …. as the result.

Your method is to read RssNews items from the data set and return about 23 items for the Feed. You need to iterate through these items And display its text in the text box, or if you can use GridView or similar controls to display these results, you need to be better.

You can try the following code in the Main method:

< p>

var s = RssReader.Read("http://ph.news.yahoo.com/rss/philippines");
StringBuilder sb = new StringBuilder();
foreach (RssNews rs in s)
{
sb.AppendLine(rs.Title);
sb.AppendLine(rs.PublicationDate);
sb.AppendLine(rs.Description );
}

textBox1.Text = sb.ToString();

This will create a string for each RssNews item and it will be displayed in textBox1 Result.

Hi, I am trying to create an RSS reader in Visual C#express. I need to read the RSS feed into a text box when the form loads. I was before I have never used RSS feeds, all the examples I encountered were done in visual studio, and it seems I can’t use it:

(XmlReader reader = XmlReader .Create(Url))

This is what I got so far. It doesn’t work.

using System;
using Sys tem.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text ;
using System.Windows.Forms;
using System.Net;

namespace WindowsFormsApplication1
{
public partial class Form1: Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
var s = RssReader.Read("http://ph.news.yahoo.com/rss/philippines");
textBox1.Text = s.ToString();
}< br /> public class RssNews
{
public string Title;
public string PublicationDate;
public string Description;
}

public class RssReader
{
public static List Read(string url)
{
var webResponse = WebRequest.Create(url).GetResponse();
if (webResponse == null)
return null;
var ds = new DataSet();
ds.ReadXml(webResponse.GetResponseStream());

var news = (from row in ds.Tables["item"].AsEnumerable()
select new RssNews
{
Title = row.Field("title"),
PublicationDate = row.Field("pubDate"),
Description = row.Field("description")
}).ToList();
return news;
}
}

I don’t know what to do. Please help.

Then your code is working Works as expected, because you are returning a list of RSSNews items, but you are assigning it to the text box in the wrong way. Doing textBox1.Text = s.ToString(); will give System.Collections.Generic.List… as Result.

Your method is to read RssNews items from the data set and return about 23 items for the feed. You need to iterate through these items and display their text in a text box, or if you You can use GridView or similar controls to display these results, you need better.

You can try the following code in the Main method:

var s = RssReader.Read("http://ph.new s.yahoo.com/rss/philippines");
StringBuilder sb = new StringBuilder();
foreach (RssNews rs in s)
{
sb.AppendLine(rs. Title);
sb.AppendLine(rs.PublicationDate);
sb.AppendLine(rs.Description);
}

textBox1.Text = sb.ToString( );

This will create a string for each RssNews item and will display the result in textBox1.

Leave a Comment

Your email address will not be published.