Monday, July 27, 2009

Rss Feeds in asp.net

To write the Rss Contents from list/datatable.

steps to follow:

Get the all the item (ex: news in a list/datatable loop through the items bind in the rss feeds format)

refer the attached image.

image 1



image 2



C#Code:

protected void Page_Load(object sender, EventArgs e)
{
this.Context.Response.ContentType = "text/xml";
this.Context.Response.ContentEncoding = Encoding.UTF8;
ShowHeader(this.Context);
NewsManager newsManager = new Telerik.News.NewsManager("News");
IList listOfNewsItems = newsManager.Content.GetContent();
if (listOfNewsItems.Count > 0)
{
foreach (IContent ICntNews in listOfNewsItems)
{
DateTime strPDate = Convert.ToDateTime(ICntNews.GetMetaData("Publication_Date"));
if (strPDate < DateTime.Now)
{
ShowItem(this.Context, ICntNews);
}
}
}

ShowFooter(this.Context);
}

private void ShowItem(HttpContext context, Telerik.Cms.Engine.IContent content)
{
context.Response.Write("");
context.Response.Write(string.Format("{0}", content.GetMetaData("Title")));
DateTime dtPubdate = Convert.ToDateTime(content.GetMetaData("Publication_Date"));
context.Response.Write(string.Format("{0}", dtPubdate.ToString("ddd, dd MMM yyyy hh:mm:ss GMT")));
context.Response.Write(string.Format("{0}", content.GetMetaData("Summary")));
context.Response.Write(string.Format("{0}://{1}{2}", context.Request.Url.Scheme, context.Request.Url.Authority, ConfigurationManager.AppSettings["NewsDetails"].ToString() + "?sNewsID=" + content.ID));
context.Response.Write(string.Format("{0}", content.ID));
context.Response.Write("
");
}

private void ShowHeader(HttpContext context)
{
context.Response.Write("");
context.Response.Write("");
context.Response.Write("");
context.Response.Write("QFC Authority news ");
context.Response.Write("News headlines ");
context.Response.Write("http://www.qfc.com.qa/ ");
context.Response.Write("http://backend.userland.com/rss ");
context.Response.Write(Environment.NewLine);
}

private void ShowFooter(HttpContext context)
{
context.Response.Write("
");
context.Response.Write("
");
}

Copyright © 2009 Angel