Introduction
This article explains how to get live updates in our website or webpage using RSS Feeds. It's very easy to get RSS Feeds in our custom page or our website.
There are the following links that can be used to get updates of C# Corner:
You can find this link in www.c-sharpcorner.com as described in the following image.
When you click there a new window opens with the XAML data.
Now open Visual Studio and follow the procedure that I am explaining here and get the live update.
Step 1
Create a web project by clicking on new project.
Step 2
Go to code behind and write the following function to read the XAML data from the *.aspx page:
- public XElement ReadXmlFromCShrpCornerPage(string CsharpCornerUrl)
- {
- HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(CsharpCornerUrl);
- WebResponse myResponse;
- myResponse = myRequest.GetResponse();
- XmlDocument _xmlDoc = new XmlDocument();
- using (Stream responseStream = myResponse.GetResponseStream())
- {
- _ xmlDoc.Load(responseStream);
- }
- return XElement.Load(new XmlNodeReader(_xmlDoc));
- }
Step 3
Now using the preceding XElement create an HTML string using the following function.
- public string CshrpCornerLiveUpdateDiv(string CsharpCornerUrl)
- { StringBuilder sb = new StringBuilder();
- var dox = ReadXmlFromCShrpCornerPage(CsharpCornerUrl);
-
- var Headting = dox.Descendants("channel").Select(d =>
- new
{
- Title = d.Element("title").Value,
- Description = d.Element("description").Value,
- Link = d.Element("link").Value,
- }).ToList();
-
- var UpdatedList = dox.Descendants("item").Select(d =>
- new
{
- Title = d.Element("title").Value,
- Description = d.Element("description").Value,
- Link = d.Element("link").Value,
- PubDate = d.Element("pubDate").Value,
-
- AuthorName = d.Element("author").Value
- }).ToList()
-
- foreach (var PageHeading in Headting)
- {
- sb.Append(" <div class=\"page\"style=\"outline: 0px; width: 1024px; margin: 0px auto; color: rgb(141, 141, 141); font-
family: Calibri, 'Segoe UI', Arial; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal;
letter-spacing: normal; line-height: normal;orphans: auto; text-align: start; text-indent: 0px; text-transform:
none; white-space: normal;widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;\">" +"
<div class=\"main\"style=\"outline: 0px; width: 1024px; float: left; margin-top: 5px; min-height: 430px; z-
index: 0; height: auto !important; background-color: rgb(255, 255, 255);\">" +
<div class=\"leftCntr\" style=\"outline: 0px; width: 676px; float: left;\">
<div class=\"recentactivityBox\"style=\"outline: 0px; width: 676px; overflow: hidden; margin: 10px 0px 0px;\">" +"
<h2 class=\"HeadingBold\" style=\"outline: 0px; color: rgb(85, 85, 85);font-size: 26px; margin: 0px; padding: 0px; font-
weight: 400; text-transform: uppercase; font-family: BebasNeueRegular;\">" + PageHeading.Title + "</h2>
<li style=\"outline: 0px; padding: 4px 0px 0px; display: block; overflow: hidden;>\"");
- }
-
-
-
- for (int i = 0; i < 5; i++)
- {
- sb.Append("<div class=\"left\" style=\"outline: 0px; width: 615px; float: clasleft; line-height: 20px;\">" +"
<h3 style=\"outline: 0px; font-size: 17px; color: rgb(51, 51, 51); font-family: Calibri; font-
weight: 400; margin: 0px; padding: 0px;\">" + "<a href=\"" + UpdatedList[i].Link + "\"" +"style=\"outline: 0px; text-
decoration: none; cursor: pointer; color: rgb(51, 51, 51);\">" +"" + UpdatedList[i].Title + "</a></h3>" +"By<span class=\"Apple-
converted-space\"> </span><a class=\"LinkRed\"" + "href=\"http://www.c-sharpcorner.com/authors/ee01e6/manish-kumar-
choudhary.aspx\"" +"style=\"outline: 0px; text-decoration: none; cursor: pointer; color: rgb(255, 102, 0); font-
family: Calibri; font-weight: 400;\">" + "" + UpdatedList[i].AuthorName + "<span class=\"Apple-converted-space\"> </span></a>
<span" +"class=\"Apple-converted-space\"> </span> On " +"" + UpdatedList[i].PubDate + "</div>");
- }
-
- sb.Append("</li></ul></div></div></div>");
- }
- return sb.ToString();
- }
Note: One can modify the CSS of this function if required for their own design and theme. Here basically I am using the C# Corner CSS design.
Step 4Now go to design mode and create a HTML server control div where we display the content of the latest update.
- <div id="CsharpBlog" runat ="server" > </div>
Step 5In the page load events of this page call the preceding function and bind the string with the CsharpBlog div.
- CsharpBlog.InnerHtml = CshrpCornerLiveUpdateDiv("http://www.c-sharpcorner.com/RSS/Blogs.aspx");
Note: In the above function call just change the URL and get a different live update like articles, blogs and so on.
When this page is run it will display like the preceding.
Wow, we did it. Now we are getting the live update of C# Corner in our page. For a better understanding of this download the source code is attached with this article.
SummaryIn this illustration you came to understand how to show a live update in our ASP.NET page.