The following code will give any page the ability to be used as an rss feed automatically
[code lang=”csharp”]
Public class BasePage : System.Web.UI.Page
{
protected override void Render(HtmlTextWriter writer)
{
if (Request.QueryString["rss"] == "true")
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
HtmlTextWriter nw = new HtmlTextWriter(sw);
Response.Clear();
writer.Write("");
writer.Write("");
writer.Write(" ");
writer.Write(" " + this.Request.Url.AbsoluteUri.ToString() + "");
writer.Write(" ");
writer.Write(" en-us");
writer.Write(" " + DateTime.Now.ToUniversalTime().ToString() + "");
writer.Write(" " + DateTime.Now.ToUniversalTime().ToString() + "");
writer.Write(" ");
writer.Write(" Dynamic page generator");
writer.Write(" ");writer.Write(" " + this.Request.Url.AbsoluteUri.ToString() + "");
writer.Write(" ");
RenderChildren(nw);
if (sb.ToString().IndexOf(" ") > 0)
writer.Write(Util.StripHTML(sb.ToString().Substring(sb.ToString().IndexOf(""))));
else
writer.Write(Util.StripHTML(sb.ToString()));
writer.Write("");
writer.Write(" " + DateTime.Now.ToUniversalTime().ToString() + "");
Guid g = new Guid();
writer.Write(" " + g.ToString() + "");
writer.Write(" ");writer.Write(" ");
}
else
{
base.Render(writer);
}
}
}
public static class Util
{
public static string StripHTML(string htmlString)
{
string pattern = @"<(.\n)*?>";
return Regex.Replace(htmlString.Replace(" ", " "), pattern, string.Empty);
}
}
[/code]