Syndicate via RSS
Taking a look at Cristian’s rss on the club’s website, and given the questions from some of you about how it was done, I feel obliged to explain it, since I see it as surprising as it is easy. By law all websites should syndicate.
The first thing is to praise the great RSSMaster library, which, as its creators explain well:
"RSSMaster is a .NET class library which helps you generate RSS feeds for your web site with a few lines of code. It supports both 0.91 (the most popular) and 2.0 (the newest) versions of RSS. RSSMaster is fully customizable and totally FREE.
To do this we will only have to put the RSSMaster.dll in the “\Bin” of our project, create a DataTable with what we want to display and pass it to the component, then we will display it on the screen and that’s it.
using Softtool.RssMaster;
STEP 0: We declare variables
String SelectString; String ConnectionString; //create an instance of the RSS generator RssGenerator rss = new RssGenerator();
STEP 1: We create the DataTable with the data to be syndicated, if our DB we should only change the ConnectionString
// We store the news in a datatable SelectString = “SELECT [id], [title], [description], [starttime], [location] FROM [Events] ORDER BY [starttime] desc”;
ConnectionString = ConfigurationManager.ConnectionStrings[“WebConfigParameter”].ConnectionString;
SqlDataAdapter da = new SqlDataAdapter(SelectString, ConnectionString); DataTable dt = new DataTable(); da.Fill(dt);
STEP 2: We mount the object that we have created from the RSSMaster
_// Initialize the RSS generator with the Club data rss.Version = RssVersion.v20; rss.Title = “Albacete DotNetClub”; //put the name of your club rss.Link = new Uri(“http://albacete.dotnetclubs.com”); //put the address of your club here rss.Description = “Albacete DotNetClub Events”; //put your description here rss.Language = “es-ES”; rss.DataSource = dt; rss.ItemPubDateField = “starttime”; rss.ItemTitleField = “title”; rss.ItemDescriptionField = “description”; rss.ItemLinkField = “id”; rss.ItemCommentsField = “location”;
STEP 3: We show the information on the screen
// Write generated RSS to output Response.Clear(); Response.ContentType = “text/xml”; rss.Generate().Save(Response.Output);
It has no more mystery, therefore, from now on I don’t want to see a single website that you set up without RSS syndication, it doesn’t take more than a few minutes and the convenience it gives you is too good to detract from.