7

I want to display RSS FEED of other website in my site made in ASP.NET. what should i do?

Muhammad Akhtar
  • 51,913
  • 37
  • 138
  • 191
bhargav
  • 99
  • 1
  • 2
  • 3

4 Answers4

14
<asp:DataList ID="DataList1" runat="server" DataSourceID="XmlDataSource1">
    <ItemTemplate>
        Title: <a href="<%# XPath("link") %>"><%# XPath("title") %></a><br />
        Pulish Date: <%# XPath("pubDate") %><br />
        Description: <%# XPath("description") %>
        <hr />
    </ItemTemplate>
</asp:DataList>

<asp:XmlDataSource ID="XmlDataSource1" Runat="server"
        DataFile="http://z.about.com/6/g/electrical/b/rss2.xml"
        XPath="rss/channel/item">
</asp:XmlDataSource>
jwheron
  • 2,553
  • 2
  • 30
  • 40
Saurabh
  • 5,661
  • 2
  • 26
  • 32
1

I myself get in a same problem and fixed finally. Use this code to solve your problem.

This code is an example but you are required to change your url and nodes of the XML in the RSS.

public static string GetRSS()
{
    try
    {
        XmlDocument newsUrl = new XmlDocument();
        newsUrl.Load("yoururl");
        XDocument doc = XDocument.Parse(newsUrl.InnerXml);
        var docs = doc.Root.Element("channel").ToString();
        newsUrl.LoadXml(docs);
        XmlNodeList idNodes = newsUrl.SelectNodes("channel/item");
        StringBuilder sb = new StringBuilder();
        int count = 0;
        count = idNodes.Count; 
        foreach (XmlNode node in idNodes)
        {
            sb.Append("<div><div><div><a href=" + node["nodename"].InnerText + ">" + node["nodename"].InnerText + "</a></div>");
            sb.Append("<div>" + node["nodename"].InnerText + "</div></div>");
            sb.Append("<div>" + node["nodename"].InnerText + "</div></div>");
           ........
        }
        return sb.ToString();          
    }
    catch (Exception ex)
    {
        throw ex;
    }
Jeetendra
  • 205
  • 3
  • 18
1

You can add external feed to Feedburner service and use BuzzBoost service to have a html code to embed to your page. This code will show the latest posts from external RSS feed.

Example of snippet:

<script src="http://feeds.feedburner.com/netrat-eu?format=sigpro" type="text/javascript" ></script><noscript><p>Subscribe to RSS headline updates from: <a href="http://feeds.feedburner.com/netrat-eu"></a><br/>Powered by FeedBurner</p> </noscript>
Vladimir Tarasov
  • 631
  • 1
  • 7
  • 10
1

Use this method to get to get feed, in this example, I am binding the Data to repeater control to show the RSS Feed.

private void GetRSS()
{
    WebRequest rssReq = WebRequest.Create("URL");

    //Create a Proxy
    WebProxy px = new WebProxy("URL", true);

    //Assign the proxy to the WebRequest
    rssReq.Proxy = px;

    //Set the timeout in Seconds for the WebRequest
    rssReq.Timeout = 5000;
    try
    {
        //Get the WebResponse
        WebResponse rep = rssReq.GetResponse();

        //Read the Response in a XMLTextReader
        XmlTextReader xtr = new XmlTextReader(rep.GetResponseStream());

        //Create a new DataSet
        DataSet ds = new DataSet();
        //Read the Response into the DataSet
        ds.ReadXml(xtr);
        //Bind the Results to the Repeater
        rssRepeater.DataSource = ds.Tables[0];
        rssRepeater.DataBind();
    }
    catch (Exception ex)
    {
        throw ex;
    }
}
Muhammad Akhtar
  • 51,913
  • 37
  • 138
  • 191