How to create RSS (Really Simple Syndication)?
/* Function for crate RSS
private void Cratetop100adsXmlRss()
{
Rssfilename = Server.MapPath("~/xml/top100ads.xml");
Process_Select_top_100_ads p = new Process_Select_top_100_ads();
p.Invoke();
xmlds = p.Top100ads;
if (xmlds != null)
{
Createrss();
}
}
{
int j = xmlds.Tables[0].Rows.Count;
if (j != 0)
{
FileStream MyFileStream = null;
StreamWriter MyWriter = null;
try
{
MyFileStream = new FileStream(Rssfilename, System.IO.FileMode.Create, System.IO.FileAccess.Write);
MyWriter = new StreamWriter(MyFileStream);
// Write header of RSS file.
MyWriter.WriteLine("<?xml version=\"1.0\"?>");
MyWriter.WriteLine("<rss version=\"2.0\" xml:base=\"http://www.viswainfotech.com\">");
MyWriter.WriteLine("<channel>");
for (int i = 0; i <= j - 1; i++)
{
MyWriter.WriteLine("<item>");
MyWriter.WriteLine("<title>" + xmlds.Tables[0].Rows[i]["title"].ToString() + "</title>");
MyWriter.WriteLine("<link>" + "http://www.listaclassified.com/viewad.aspx?cid=" + xmlds.Tables[0].Rows[i]["classifiedid"].ToString() + "&" + "mid=" + xmlds.Tables[0].Rows[i]["memberid"].ToString() + "</link>");
MyWriter.WriteLine("<description>"
+ "<![CDATA[ <img src=" +"../Image/" + xmlds.Tables[0].Rows[i]["memberid"].ToString()+"/S_" +xmlds.Tables[0].Rows[i]["classifiedid"].ToString()+ ".png />]]>" + xmlds.Tables[0].Rows[i]["description"].ToString() +
"</description>");
MyWriter.WriteLine("<pubDate>" + xmlds.Tables[0].Rows[i]["c_date"].ToString() + "</pubDate>");
MyWriter.WriteLine("</item>");
}
MyWriter.WriteLine("</channel>");
MyWriter.WriteLine("</rss>");
}
catch (Exception excep)
{
Response.Write("Error: " + excep.Message);
}
finally
{
MyWriter.Close();
MyFileStream.Close();
}
}
}
/* after run this code the .xml file can be create like this.
<?xml version="1.0"?>
<rss version="2.0" xml:base="http://www.listaclassified.com">
<channel>
<item>
<title>name of ads title</title>
<link>http://www.listaclassified.com/viewad.aspx?cid=13032009003352312&mid=M120320092235381561</link>
<description><![CDATA[ <img src=../Image/M120320092235381561/S_13032009003352312.png />]]>.....</description>
<pubDate>3/13/2009 12:00:00 AM</pubDate>
</item>
<item>
<title>adsds</title>
<link>http://www.listaclassified.com/viewad.aspx?cid=13032009003859390&mid=M120320092235381561</link>
<description><![CDATA[ <img src=../Image/M120320092235381561/S_13032009003859390.png />]]>.....</description>
<pubDate>3/13/2009 12:00:00 AM</pubDate>
</item>
<item>
<title>sas</title>
<link>http://www.listaclassified.com/viewad.aspx?cid=13032009033606796&mid=M130320090335155461</link>
<description><![CDATA[ <img src=../Image/M130320090335155461/S_13032009033606796.png />]]>.....</description>
<pubDate>3/13/2009 12:00:00 AM</pubDate>
</item>
<item>
<title>sale for cars</title>
<link>http://www.listaclassified.com/viewad.aspx?cid=13032009041122812&mid=M130320090409385151</link>
<description><![CDATA[ <img src=../Image/M130320090409385151/S_13032009041122812.png />]]>S D SDSSDSD SDSDSDSD.....</description>
<pubDate>3/13/2009 12:00:00 AM</pubDate>
</item>
<item>
<title>Test ad 1</title>
<link>http://www.listaclassified.com/viewad.aspx?cid=13032009042123046&mid=M120320092235381561</link>
<description><![CDATA[ <img src=../Image/M120320092235381561/S_13032009042123046.png />]]>.....</description>
<pubDate>3/13/2009 12:00:00 AM</pubDate>
</item>
<item>
<title>55555555555555555</title>
<link>http://www.listaclassified.com/viewad.aspx?cid=13032009053450531&mid=M120320092235381561</link>
<description><![CDATA[ <img src=../Image/M120320092235381561/S_13032009053450531.png />]]>.....</description>
<pubDate>3/13/2009 12:00:00 AM</pubDate>
</item>
</channel>
</rss>
If you create auto generate rss feed true for web browser
Write this code in your .aspx file.
protected void Page_Load(object sender, EventArgs e)
{
Masterpage_MasterPage mastertitel = (Masterpage_MasterPage)Master;
mastertitel.Settitle("Placeads");
mastertitel.Setlinktag("Listaclassified top feeds", "link001", "../xml/top100ads.xml");
}
Write this code in master page.
If the user in session then rss can attach.
{
HtmlHead headtag = (HtmlHead)Page.Header;
HtmlLink linktag = new HtmlLink();
if (Session["memberid"] != null)
{
linktag.ID = id;
linktag.Href = href;
linktag.Attributes.Add("rel", "alternate");
linktag.Attributes.Add("type", "application/rss+xml");
if (title.Length > 10)
{
title = title.Substring(1, 10);
linktag.Attributes.Add("title", title);
}
else
{
linktag.Attributes.Add("title", title);
}
headtag.Controls.Add(linktag);
}
else
{
linktag.ID = id;
linktag.Href = href;
linktag.Attributes.Add("rel", "alternate");
linktag.Attributes.Add("type", "application/rss+xml");
if (title.Length > 10)
{
title = title.Substring(1, 10);
linktag.Attributes.Add("title", title);
}
else
{
linktag.Attributes.Add("title", title);
}
headtag.Controls.Add(linktag);
}
}

Steve BPosted May 14, 2009, 2:59 AM
The namespace System.ServiceModel.Syndication is already providing reading and writing feeds fucntionnality (rss or atom).