Quantcast
Channel: Consuming WordPress RSS Feed In ASP.NET - Stack Overflow
Viewing all articles
Browse latest Browse all 7

Answer by Sean Kendle for Consuming WordPress RSS Feed In ASP.NET

$
0
0

This is simply @Christophe Geers's great solution converted to VB, as a function:

Protected Function getWordPressFeed(ByVal strUrl As String) As DataTable    Dim rssFeed = New Uri(strUrl)    Dim request = DirectCast(WebRequest.Create(rssFeed), HttpWebRequest)    request.Method = "GET"    Dim response = DirectCast(request.GetResponse(), HttpWebResponse)    Dim feedContents As String    Using reader = New StreamReader(response.GetResponseStream())        feedContents = reader.ReadToEnd()    End Using    Dim document = XDocument.Parse(feedContents)    Static Dim dcNamespace As XNamespace    dcNamespace = "http://purl.org/dc/elements/1.1/"    Dim posts = (From p In document.Descendants("item") Select New With { _        Key .Title = p.Element("title").Value, _        Key .Link = p.Element("link").Value, _        Key .Author = p.Element(dcNamespace +"creator").Value, _        Key .Description = p.Element("description").Value, _        Key .PubDate = DateTime.Parse(p.Element("pubDate").Value) _    }).ToList()    Dim dataSet = New DataSet()    Dim blog = New DataTable("Blog")    blog.Columns.Add("Title", GetType(String))    blog.Columns.Add("Link", GetType(String))    blog.Columns.Add("Description", GetType(String))    blog.Columns.Add("Author", GetType(String))    blog.Columns.Add("PubDate", GetType(DateTime))    dataSet.Tables.Add(blog)    For Each post In posts        Dim newRow = blog.NewRow()        newRow("Title") = post.Title        newRow("Link") = post.Link        newRow("Description") = post.Description        newRow("Author") = post.Author        newRow("PubDate") = post.PubDate        blog.Rows.Add(newRow)    Next    Return blogEnd Function

Viewing all articles
Browse latest Browse all 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>