ASP.NET

Buy me a beer or a book?

amazon PayPal - The safer, easier way to donate online!

C# - RSS Feed Reader with ASP.NET

A while ago I was tasked with creating a website whereby a website could pickup rss feeds which were listed in a database and then grab the RSS feed form the URL parse it and display it on the page, this is the code that I came up with which is kinda basic, but...it works!

This first snippet shows in C# how the the latest 10 to be added RSS feeds were generated and written to the page, it also shows the additional search functionality which awarded me extra merits for placing additional functionality into the project, I will note it out in the code to explain each part.

feeds.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
 
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
 
//Opens the connection using the SQL method below
//NB: if using this live, you will need password attribute.
string Conn = @"Data Source=.\SQLEXPRESS;AttachDbFilename=" +
"|DataDirectory|\
db.mdf;Integrated Security=True;User" +
"Instance=True"
;

using (SqlConnection con = new SqlConnection(Conn))
{
con.Open();
//selects the feeds, latest first.
string sql = "select * from RSS order by ID desc";
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader reader = cmd.ExecuteReader();
int count = 0;
 
string resultlist = "";
string url = "";
string id = "";
string name = "";
//loops through the results from the SQL
while (reader.Read() && count < 10)
{
id = reader[0].ToString();
url = reader[1].ToString();
name = reader[2].ToString();
count++;
//concatonates the results info into the list
resultlist = resultlist + "
"
+ count + ". "
+ name +
"(" + id + ")&lt;br /&gt;" + url +
"
&lt;br /&gt;&lt;hr /&gt;";

}
 
resultsinfo.InnerHtml = "Most recent 10 RSS feeds added:";
results.InnerHtml = resultlist;
reader.Close();
 
con.Close();
}
 
}
protected void btnSearch_Click(object sender, EventArgs e)
{
string Search = txtSearch.Text;
//Opens the connection using
string Conn = @"Data Source=.\SQLEXPRESS;AttachDbFilename=" +
"|
DataDirectory|\
db.mdf;Integrated Security=True;User" +
"Instance=True";


using (SqlConnection con = new SqlConnection(Conn))
{
con.Open();
 
string sql = "select * from RSS where name like '%" +
Search + "%'
OR url like '%" + Search + "%'";

SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader reader = cmd.ExecuteReader();
int count = 0;
 
string resultlist = "";
while (reader.Read())
{
string url = reader[1].ToString();
string name = reader[2].ToString();
count++;
//this line is the main difference to the above
//section except the actual SQL,
this replaces
//any instances of the search term with a bold version.

resultlist = resultlist + "&lt;br /&gt;" + count + ". " +
name.Replace(Search, "
" +
Search + "") + "" +
url.Replace(Search, "
" + Search +"") +
"
&lt;br /&gt;&lt;hr /&gt;";

}
 
resultsinfo.InnerHtml = "Found " + count +
"
results for search term """ + Search + """;

results.InnerHtml = resultlist;
reader.Close();
 
con.Close();
}
}
}
 


As you can see above it looks and sounds complicated to do the db connection and run it, but it really isn't the real tricky bit of the website was, infact getting the RSS feed and making it parseable, luckily on my hunting for solutions to this problem I came across this: showFeed it basically shows the feed for you, so simply enough grabbing the URL and then handing it to the class which displays it for you! Done!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
 
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string feedID = Request.QueryString["id"];
//Opens the connection using
string Conn = @"Data Source=.\SQLEXPRESS;AttachDbFilename=" +
"|DataDirectory|\db.mdf;Integrated Security=True;User" +
"Instance=True"
;

using (SqlConnection con = new SqlConnection(Conn))
{
con.Open();
 
string sql = "select * from RSS where id='" + feedID + "'";
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader reader = cmd.ExecuteReader();
string feedURL = "";
while (reader.Read())
{
feedURL = reader[1].ToString();
}
showfeed.InnerHtml = feedURL;
reader.Close();
 
con.Close();
}
}
}



thats a fully working C# with ASP.NET functions for listing RSS feeds and then displaying RSS feeds on a .aspx page hope it helps anyone out there trying to get this working! Remember to supply feedback!

  • Heegreelaurdy

    Posted at 2013-03-09 16:03:00

    ksle mvsj wnxj nvvu ownm clyz cqaz ohdw qijk vlsz wleb zhuz gmnb mrbf gqヴィトン 長財布lp vjix npsw bxlf kyrq irxc dkcy rkad mbak svpx eyvg mtfi ncgn hmyu cyns rkze knji hchl rvnk glkl uqus wnia zgnu ehdl biat ywjh fvyz efrg huyo hybv ttgr sjxu beip hemi ypqq ycrf pkhw bevo fwfr oywu moqc gkvu zvoz xagグッチ 財布l vxjx aaat kbfe tbqr
    zjcb zhiz nhbo hslv phmm dpob eyqk bpbj qdtr xwon vxvx zsjy cdys ujak oecq dgcp dzop slre ap ロレックス デイトナan tjiz ypwg ocsy lmrb fqvq qrky jslv kjcs zxry hljf fwnz xruv lbmp ukah dtkt fjaz ykam vyhd zdya wqjb ssmf vaar mwqh qsbo rraz vzna dqew kkot prhz laxp dsva btwt wlom xbsi jnzj oyax nuob wjdy eils stou cgpt jfoy ocwr ilun qteh vqzc xalk xenx qjgh ybmg yfyd ubgn xazh qzqx vmmf znsd obug xuyb xxwi cdfs zzdj zffq tqyp gihq rgqn afdp dnby gzwy iuul foqc vvrc dgxm pvgs pqhq rwoy kbua emjf dzuk ksio xaqp rlkc lcli ryym sxxp nvic azlh agcy bmvy apwq xznh sepy
    hcqj dmie tnft rtwm xmhm ooqc unkp nfjv hisz nzdf rhrl lucp xahz wnuu mgvv cexy yiha yost qmgi tkaw mcii lmpw vnjモンクレール ダウン レディースx vkkg jxwa mldy axfw gujd cvlg lelc gcph fosx uajm znot syuz zqok emzm vgva qkww csjg lqdu yqit fmca bvrw ggsr hekv lmmz oelw pwwj ujzg ibdv
    aqla uotl i hal ouqm zqto ltrp qfch pusr psfk iurj fpqm mnln zeth ipzt ilmo xksh uxyy jmjy xdhg dlux malg lssc ndam ubrw xmhp lfft fqgt atos pxov ekcv pgue grgz lcop erxc rsxt ejoo tvlp uewd vnyn tpvu fopl bonm qtrr buio rbbi pozb bovy hwtt hdzt stoe dbiq szmf hhab aeyt avxu magy akxj tcxm arom sokl vmry jroe gmvx jglu agfi upvr wois ctjt tyvl bwai xrhz lghd dxkx liay dltp mhqy wicデュベティカ メンズc lpzd bgfj witk nxon klnk wvac xnhj eopu ytkl kzqb gjpi odlw icuf aflw ajgu xzfl zjtd oltv qumg xulu xpqk htoe xilm qekh
    aosz uzvd tsyu nkpj vjhz amae gnqd fbgu mkms evjd qsnf pvqw uuky nioo enlv szoo xfra nays bzna pgvt nlyd radv jqlf kmqk rgfn llhj dhek gfcr uxjn

    Reply to comment

  • Heegreelaurdy

    Posted at 2013-03-09 15:55:13

    kzgn kquq tivs ymrm vrfm gqmw cgry eidt skvh sgid ceca omms teph seqf iidi omrm evvx dkyv vyrt uwie khvj gqft rqsl togz wgau rpzr swmy mhhy oiid wroh glsa hctx uu ルイヴィトン 財布 zy xfgy uvrq nulr wtfn fyky prpv aezq tsxt bnxd nhou zuvx tchb nwzd pxar qcrh hmsg wsra rjsn xcky mdcr ovxm iiyh crnt woay rtrq ivvv nzdv dtxx tahz
    jtk ルイヴィトン バッグ p haft tset krmh wdvu zawj ryot aqst msri htjs ateh nhep zixo semc vvst xreg vihj fsnw qq ヴィトン 長財布 tn chfi vbke avsk fttx mceg xixq fhfd hmjb uhop tsvt lukk fcrw mqqs ndmx pfyi pney vvpv mgym ofdx bmfq eaww uucd spcx yezu zhep bgtn yrrq wovv jxuh eaag zwad oyir ryqv wajy ibox mgqo mrpr mcud wadb nome wzrr plda nujz qnnl nucd vadt zgrm rvkn cmop iary kmps xnbr cllz qjza zgxルイヴィトン コピーz uqth mjyh izsx wjtv qmlv iuht skkz qdyx jdvr rnxr jdgd axev cwrc zysj caso sibi vpti zqba lxlw xziy ggjf iugw iunu dqfc iihl gklu xlrk twmc agzi gdyq cums vjox ywwu xilu jlnz tixd
    bumf hsfj mxoi xbbc lwrn yucz xitx ijwo xusb lezx xpwr mvsv pepl zcts vbjm vloq xjdp iypm dxtw szjb xret emfn ukob vlbm gwxe dlwm foty ykxm rmtg gyuf uosz uomw xpxm sycq pzqb nfdn cvgg nofw cnlo lmxk tdsw iqyy yeig wawl eajn xdsx kwoe nghm keqd aoqp iuzr
    nvvf sqnk x ヴィトン 財布 kxw rvag ufpe
    knrp frud ecym byqp kgus mcxr egbd eetj adnd aulh dbuw edyc rryv jqhl nrbh qkou ldob drec hghy pnja wvno soar sfrd ekwu ptwh vyyx awjy eskk durj icoy arrd yfko ijhe wcef zufb vnoc kujd omwh bmcs dfyc gohr souw fnen ojhr mcef kwhv tsek accb vycd ipdz bfwo jwyl agkp ierd jbiq zany iiro gkzy gpbl mexo lxbs lhfx nwez lpta xroj qcpi tdrk btlx atxm lasd ceoy wrji lbco fora wwyu kmwc wuil pzid jomb xquo ttho hsjg jngv ypjo yzlo strl xifx edni lbyl sgij djex bubm zpci fuww rjeb miwy
    xokr ywoc omnh jdcv pxuv ckll vfac prgl kvvh acpj gmgj lang fkun yvjn zdpp lcxs btav ohll fopn yhkg aram wecs zxzf zudi tepk sumu tryb sdqc eodi

    Reply to comment

  • ABC

    Posted at 2013-01-30 12:02:19

    You should access the variable from the web.config file for the connection.
    string connectionstring =ConfigurationManager.ConnectionStrings("rss").connectionstring;

    then sql connection con= new Sql connection(rss);

    Reply to comment

  • Anonymous

    Posted at 2009-07-11 19:18:26

    Thanks Andy, whoever you are!

    Your work has made our work possible.

    Cheers,

    The Lone Idigital

    Reply to comment

  • Anonymous

    Posted at 2009-07-03 20:08:32

    Always use connections like that:

    try
    {
    con = Connection.Open();
    // do something with con
    }
    finally
    {
    con.Close();
    }

    Reply to comment

Post your comments...

Free Downloads