获取RSS链接

时间:2012-09-13 02:16:06

标签: c# rss

我有一个Feed阅读器并在列表框中获取标题,但如何为标题插入值链接?

private void Form1_Load(object sender, EventArgs e)
{
    var reader = XmlReader.Create("http://feeds.feedburner.com/myusername?format=xml");
    var feed = SyndicationFeed.Load<SyndicationFeed>(reader);

    foreach (var item in feed.Items)
    {
       listBox1.Items.Add(item.Title.Text);
       listBox1."add value link" = item.Links."Text";
    }
}

private void listBox1_Click(object sender, EventArgs e)
{          
    MessageBox.Show(listBox1."value link for item selected".ToString());
}

如果点击标题显示链接

Ex:点击my feed2 show wwww/mywebsite/myfeed2

1 个答案:

答案 0 :(得分:1)

如果你想链接rss title和它的url,你必须用title和url属性编写自己的类,并为listbox编写自定义项模板,或者只是定义一个字典。

private Dictionary<string,string> dictionary = new Dictionary<string,string>();

foreach (var item in feed.Items)
        {
            dictionary.Add(item.Title.Text, item.Links.Text);
            listBox1.Items.Add(item.Title.Text);

        }



private void listBox1_Click(object sender, EventArgs e)
  {   
      string url = dictionary[listBox1.SelectedValue];       
      MessageBox.Show(url);
  }