Your SlideShare is downloading. ×
0
Creating an RSS feed
Creating an RSS feed
Creating an RSS feed
Creating an RSS feed
Creating an RSS feed
Creating an RSS feed
Creating an RSS feed
Creating an RSS feed
Creating an RSS feed
Creating an RSS feed
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Creating an RSS feed

1,559

Published on

Creating and displaying RSS feed by using LINQ asp.net …

Creating and displaying RSS feed by using LINQ asp.net
by
http://www.livetolearn.in

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,559
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. RSS Feed using ASP.NET & Linq http://www.livetolearn.in
  • 2. <ul><li>RSS is a format for an XML document that describes a list of items, such as blog entries or news headlines. </li></ul><ul><li>The document may just be a stream of XML created on the fly rather than a static file. </li></ul>http://www.livetolearn.in
  • 3. <ul><li>&lt;rss&gt; </li></ul><ul><li>&lt;channel&gt; </li></ul><ul><li>&lt;item&gt; </li></ul><ul><li>&lt;title&gt;&lt;/title&gt; </li></ul><ul><li>&lt;description&gt;&lt;/description&gt; </li></ul><ul><li>&lt;link&gt;&lt;/link&gt; </li></ul><ul><li>&lt;pubDate&gt;&lt;/pubDate&gt; </li></ul><ul><li>&lt;!--..............................--&gt; </li></ul><ul><li>&lt;/item&gt; </li></ul><ul><li>&lt;/channel&gt; </li></ul><ul><li>&lt;/rss&gt; </li></ul>http://www.livetolearn.in
  • 4. <ul><li>Add a generic handler named rsshandler.ashx </li></ul><ul><li>Add import directive Imports System.Xml.Linq </li></ul><ul><li>Replace the process request() subroutine as follows </li></ul>http://www.livetolearn.in
  • 5. <ul><li>Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest </li></ul><ul><li>Dim rssdoc As New XDocument(New XDeclaration( &amp;quot;1.0&amp;quot;, Nothing, Nothing)) </li></ul><ul><li>rssdoc.Add( New XComment( &amp;quot;My RSS Feed uses XML to Linq datasource&amp;quot;)) </li></ul><ul><li>Dim rssrootelement As New XElement( &amp;quot;rss&amp;quot;, New XAttribute( &amp;quot;version&amp;quot;, &amp;quot;2.0&amp;quot;)) </li></ul><ul><li>Dim rsschannel As New XElement( &amp;quot;channel&amp;quot;) </li></ul><ul><li>Dim rsstitle As New XElement( &amp;quot;title&amp;quot;, &amp;quot;RK&apos;s News Channel&amp;quot;) </li></ul><ul><li>rsschannel.Add(rsstitle) </li></ul><ul><li>Dim rssdesc As New XElement( &amp;quot;description&amp;quot;, &amp;quot;Description of Channel&amp;quot;) </li></ul><ul><li>rsschannel.Add(rssdesc) </li></ul><ul><li>Dim rsslink As New XElement( &amp;quot;link&amp;quot;, &amp;quot;http://www.livetolearn.in/&amp;quot;) </li></ul><ul><li>rsschannel.Add(rsslink) </li></ul><ul><li>Dim intCtr As Integer </li></ul><ul><li>Dim rssitem As XElement </li></ul>RSS Document Comment RSS Channel Title (Appears at title bar) RSS Title Link http://www.livetolearn.in
  • 6. <ul><li>For intCtr = 0 To 10 </li></ul><ul><li>rssitem = New XElement( &amp;quot;item&amp;quot;, _ </li></ul><ul><li>New XElement( &amp;quot;title&amp;quot;, &amp;quot;This is item number &amp;quot; &amp; intCtr.ToString), _ </li></ul><ul><li>New XElement( &amp;quot;description&amp;quot;, &amp;quot;Description for item # &amp;quot; &amp; _ </li></ul><ul><li>intCtr.ToString), _ </li></ul><ul><li>New XElement( &amp;quot;link&amp;quot;, &amp;quot;http://www.livetolearn.in/item&amp;quot; &amp; _ </li></ul><ul><li>intCtr.ToString &amp; &amp;quot;.aspx&amp;quot;)) </li></ul><ul><li>rsschannel.Add(rssitem) </li></ul><ul><li>Next </li></ul><ul><li>rssrootelement.Add(rsschannel) </li></ul><ul><li>rssdoc.Add(rssrootelement) </li></ul><ul><li>rssdoc.Save(( New System.IO.StreamWriter _ </li></ul><ul><li>(context.Response.OutputStream))) </li></ul><ul><li>End Sub </li></ul>This for loop creates 10 sample items with Description. http://www.livetolearn.in
  • 7. <ul><li>Now, browse the rsshandler.ashx with Internet Explorer 7 and above or Firefox </li></ul>http://www.livetolearn.in
  • 8. Displaying XML data http://www.livetolearn.in
  • 9. <ul><li>Add an XmlDataSource control to a ASP.NET page </li></ul><ul><li>Click smart tag </li></ul><ul><li>Choose configure data source </li></ul><ul><li>Enter the URL of the RSS feed </li></ul><ul><li>For example </li></ul><ul><li>http://www.livetolearn.in/blog/?feed=rss2 </li></ul><ul><li>Type the following in Xpath expression text box </li></ul><ul><li>Rss/channel/item </li></ul><ul><li>Add a data list control and set source to Xmldatasource1, </li></ul><ul><li>Edit Item template of data list control </li></ul><ul><li>Add a hyper link control inside the item template </li></ul><ul><li>Set it’s data binding property as follows Navigate URL – xPath(“link”) </li></ul><ul><li>xPath(“title”) </li></ul><ul><li>It displays the list of items from rss feed. </li></ul>http://www.livetolearn.in
  • 10. <ul><li>By adding more items in Item Template (e.g. Text box), we can display description from RSS feed. </li></ul><ul><li>******** </li></ul>http://www.livetolearn.in

×