c# - How to Save BBC RSS Feed with Images url into Database? -


i'm creating asp.net website showing rss feed bbc, i'm doing want m showing rss feed on asp:datalist problem dont want show feed directly xml document, want store firstly database , show website using datalist. older code is

<asp:datalist id="datalist1" runat="server" datasourceid="xmldatasource1">   <itemtemplate> <div class="jumbotron"> <h2><%# xpath("title") %></h2> <br /> <h3><%# xpath("pubdate") %></h3> <br /> <h3><%# xpath("description") %></h3> <br /> <asp:repeater runat="server" id="_subitemsrepeater"   enableviewstate="false"   datasource='<%# xpathselect("media:thumbnail", xmlnamespacemanager) %>'>   <itemtemplate>     <img src="<%# ((system.xml.xmlnode)container.dataitem).attributes["url"].value %>" />     <br />   </itemtemplate>   </asp:repeater>   <br />   <a class="btn btn-primary btn-lg" target="_blank" href="<%# xpath("link") %>">read more on story</a>   </div>   <hr /> </itemtemplate> </asp:datalist> <asp:xmldatasource id="xmldatasource1" runat="server" datafile="http://feeds.bbci.co.uk/news/education/rss.xml" xpath="rss/channel/item" /> 

c# code in page load

public partial class _default : page { protected xmlnamespacemanager xmlnamespacemanager { get; set; }  protected void page_load(object sender, eventargs e) {     xmlnamespacemanager =  new     xmlnamespacemanager(xmldatasource1.getxmldocument().nametable);  xmlnamespacemanager.addnamespace("media", "http://search.yahoo.com/mrss/"); }  } 

and new code is:

       filewebrequest rssfeed = (filewebrequest)webrequest.create(feedurl);        // dataset rssdata = new dataset();        //read xml stream of web request          xdocument xd =     xdocument.load(rssfeed.getresponse().getresponsestream());         xnamespace media = "http://feeds.mashable.com/mashable?format=xml";         foreach (var feed in xd.descendants("item"))         {             string title = feed.element("title").value.tostring();             string description = feed.element("description").value.tostring();             string link = feed.element("link").value.tostring();             datetime pubdate = datetime.parse(feed.element("pubdate").value);             string thumb = (string)feed.element(media + "thumbnail") != null ? (string)feed.element(media + "thumbnail").attribute("url").value.tostring() : "file:///c:/no_image.png";             string connection = configurationmanager.connectionstrings["defaultconnection"].tostring();             sqlconnection newcon = new sqlconnection(connection);             newcon.open();             sqlcommand newcmd = new sqlcommand(tablename + "_proc", newcon);             newcmd.commandtype = commandtype.storedprocedure;             newcmd.parameters.addwithvalue("@title", title);             newcmd.parameters.addwithvalue("@description", description);             newcmd.parameters.addwithvalue("@link", link);             newcmd.parameters.addwithvalue("@pubdate", pubdate);             newcmd.parameters.addwithvalue("@thumb", thumb);             newcmd.executenonquery();             newcon.close();         }    

in code problem images returns me noimage.jpg every time i'm connected internet. think there no problem namespace too. i'm doing because if feed server or news server shutdown or not respond website not effected so. know how resolve issue?. appreciated. !


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -