<body>
<form id="form1" runat="server">
<div>
</div>
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<table class="NormalText" runat="server" id="tbl_Feed_Reader" cellpadding="0" cellspacing="0">
</table>
</td>
</tr>
</table>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</form>
</body>
protected void Button1_Click(object sender, EventArgs e)
{
int proxyValue = 8080;
WebProxy proxyObject = new WebProxy("http://proxy:8080/",true);
proxyObject.Credentials = CredentialCache.DefaultCredentials;
WebRequest MyRssRequest = WebRequest.Create("http://www.csharp-dotnet-interview-questions.blogspot.com/feeds/posts/default?alt=rss");
MyRssRequest.Proxy = proxyObject;
WebResponse MyRssResponse = MyRssRequest.GetResponse();
Stream MyRssStream = MyRssResponse.GetResponseStream();
// Load previously created XML Document
XmlDocument MyRssDocument = new XmlDocument();
MyRssDocument.Load(MyRssStream);
XmlNodeList MyRssList = MyRssDocument.SelectNodes("rss/channel/item");
string sTitle = "";
string sLink = "";
string sDescription = "";
// Iterate/Loop through RSS Feed items
for (int i = 0; i < MyRssList.Count; i++)
{
XmlNode MyRssDetail;
MyRssDetail = MyRssList.Item(i).SelectSingleNode("title");
if (MyRssDetail != null)
sTitle = MyRssDetail.InnerText;
else
sTitle = "";
MyRssDetail = MyRssList.Item(i).SelectSingleNode("link");
if (MyRssDetail != null)
sLink = MyRssDetail.InnerText;
else
sLink = "";
MyRssDetail = MyRssList.Item(i).SelectSingleNode("description");
if (MyRssDetail != null)
sDescription = MyRssDetail.InnerText;
else
{
sDescription = "";
}
// Now generating HTML table rows and cells based on Title,Link & Description
HtmlTableCell block = new HtmlTableCell();
block.InnerHtml = "<span style='font-weight:bold'><a href='" + sLink + "' target='new'>"+ sTitle + "</a></span>";
HtmlTableRow row = new HtmlTableRow();
row.Cells.Add(block);
tbl_Feed_Reader.Rows.Add(row);
HtmlTableCell block_description = new HtmlTableCell();
block_description.InnerHtml = "<p align='justify'>" + sDescription + "</p>";
HtmlTableRow row2 = new HtmlTableRow();
row2.Cells.Add(block_description);
tbl_Feed_Reader.Rows.Add(row2);
}
}
GOOD One Thanks...
ReplyDelete