Nello script #942 si è visto come creare un feed RSS o Atom utilizzando le classi presenti nel .NET Framework 3.5.

Queste classi formatter permettono anche la lettura dei feed forniti da altri servizi. Ecco del semplice codice per leggere le informazioni provenienti dal blog presente su questo sito:

using System;
using System.Xml;
using System.Linq;
using System.ServiceModel.Syndication;

namespace RssGenerator
{
  public partial class ReadFeed : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      var reader = XmlReader.Create("http://blogs.aspitalia.com/rss.aspx");
      var formatter = new Rss20FeedFormatter();
      formatter.ReadFrom(reader);

      var coll = from c in formatter.Feed.Items
             select new
             {
               Id = c.Id,
               Title=c.Title.Text,
               Category=c.Categories[0].Name,
               Name=c.Authors.Count,
               Date= c.PublishDate.ToString(),
               Body=c.Summary.Text
             };

      feeds.DataSource = coll;
      feeds.DataBind();
    }
  }
}

Nella pagina basterà inserire una normale GridView per visualizzare il risultato:

<asp:GridView ID="feeds" runat="server" AutoGenerateColumns="true" />

Per maggiori informazioni si veda:
#942 - Creare feed RSS e Atom con il .NET Framework 3.5
https://www.aspitalia.com/script/942/Creare-Feed-RSS-Atom-.NET-Framework-3.5.aspx

Commenti

Visualizza/aggiungi commenti

| Condividi su: Twitter, Facebook, LinkedIn

Per inserire un commento, devi avere un account.

Fai il login e torna a questa pagina, oppure registrati alla nostra community.

Approfondimenti

I più letti di oggi