|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionWith this library, you can easily create some RSS 2.0 files for your site and/or use (display) some RSS 2.0 files from other sites into your site. Create RSS 2.0Create RSS 2.0 Sample (1):For seeing this source code, you should see the create_rss2_sample1.aspx.cs file. In this source code, you see that I created a private void Page_Load(object sender, System.EventArgs e)
{
IranianExperts.RSS.RSSChannel oRSSChannel =
new IranianExperts.RSS.RSSChannel("Channel Title",
"Channel Link", "Channel Description");
oRSSChannel.PubDate = System.DateTime.Now.ToString();
IranianExperts.RSS.RSSRoot oRSSRoot =
new IranianExperts.RSS.RSSRoot(oRSSChannel,
Response.OutputStream);
IranianExperts.RSS.RSSItem oRSSItem = null;
oRSSItem = new IranianExperts.RSS.RSSItem("Item 1", "http://www.item1.com/");
oRSSItem.PubDate = System.DateTime.Now.ToString();
oRSSRoot.Items.Add(oRSSItem);
oRSSRoot.Items.Add("Item 2");
oRSSRoot.Items.Add("Item 3", "http://www.item3.com/");
Response.Clear();
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "text/xml";
IranianExperts.RSS.RSSUtilities.PublishRSS(oRSSRoot);
Response.End();
}
Create RSS 2.0 Sample (2):For seeing this source code, you should see the create_rss2_sample2.aspx.cs file. This sample is too similar to Create RSS 2.0 sample (1), but in this sample I created the other object with the name of private void Page_Load(object sender, System.EventArgs e)
{
IranianExperts.RSS.RSSChannel oRSSChannel =
new IranianExperts.RSS.RSSChannel("Channel Title",
"Channel Link", "Channel Description");
oRSSChannel.PubDate = System.DateTime.Now.ToString();
IranianExperts.RSS.RSSImage oRSSImage =
new IranianExperts.RSS.RSSImage(
"http://www.site.com/images/banner.gif",
"http://www.iranianexperts.com/", "Iranian Experts");
IranianExperts.RSS.RSSRoot oRSSRoot =
new IranianExperts.RSS.RSSRoot(oRSSChannel,
oRSSImage, Response.OutputStream);
IranianExperts.RSS.RSSItem oRSSItem = null;
oRSSItem =
new IranianExperts.RSS.RSSItem("Item 1", "http://www.item1.com/");
oRSSItem.PubDate = System.DateTime.Now.ToString();
oRSSRoot.Items.Add(oRSSItem);
oRSSRoot.Items.Add("Item 2");
oRSSRoot.Items.Add("Item 3", "http://www.item3.com/");
Response.Clear();
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "text/xml";
IranianExperts.RSS.RSSUtilities.PublishRSS(oRSSRoot);
Response.End();
}
Displaying RSS 2.0 Files in Your SiteFor displaying some RSS 2.0 files in your some .aspx files, you must put one <asp:datagrid id="grdData" cellpadding="3"
autogeneratecolumns="False" font-name="Tahoma"
font-size="8pt" runat="server" bordercolor="#E7E7FF"
borderstyle="None" borderwidth="1px" backcolor="White"
gridlines="Horizontal" font-names="Tahoma">
<alternatingitemstyle backcolor="#F7F7F7">
</alternatingitemstyle>
<itemstyle forecolor="#4A3C8C" backcolor="#E7E7FF">
</itemstyle>
<headerstyle font-size="8pt" font-bold="True"
horizontalalign="Center" forecolor="#F7F7F7" backcolor="#4A3C8C">
</headerstyle>
<columns>
<asp:templatecolumn headertext="Some Recent Titles Posts...">
<itemtemplate>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
And raise private void grdData_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
switch(e.Item.ItemType)
{
case System.Web.UI.WebControls.ListItemType.Item:
case System.Web.UI.WebControls.ListItemType.SelectedItem:
case System.Web.UI.WebControls.ListItemType.AlternatingItem:
System.Data.DataRowView oDataRowView =
(System.Data.DataRowView) e.Item.DataItem;
string strLINK = oDataRowView["LINK"].ToString();
string strTITLE = oDataRowView["TITLE"].ToString();
int intTitleMaxLenght = 20;
if(strLINK == "")
{
if(strTITLE.Length <= intTitleMaxLenght)
e.Item.Cells[0].Text = strTITLE;
else
e.Item.Cells[0].Text =
strTITLE.Substring(0, intTitleMaxLenght - 1) + " ...";
}
else
{
if(strTITLE.Length <= intTitleMaxLenght)
e.Item.Cells[0].Text =
"<a href='" + strLINK + "' target='_blank'>" + strTITLE + "</a>";
else
e.Item.Cells[0].Text =
"<a href='" + strLINK + "' target='_blank'>" +
strTITLE.Substring(0, intTitleMaxLenght - 1) + " ...</a>";
}
break;
}
}
So, depending on how you want to display RSS 2.0 files (from Local Drive or URL address), you must write one of these source codes that will be useful for you. For Local Drive (in your site): strPathName = Server.MapPath("rss") + "file://RSS2Sample1.xml/";
grdData.DataSource =
IranianExperts.RSS.RSSUtilities.GetRSSFeed(
IranianExperts.RSS.RSSLocation.Drive,
strPathName, IranianExperts.RSS.RSSFeedType.item);
grdData.DataBind();
For URL address (Using some RSS 2.0 files from other sites): strPathName = "http://localhost/working_on_rss/rss/RSS2Sample1.xml";
grdData.DataSource =
IranianExperts.RSS.RSSUtilities.GetRSSFeed(
IranianExperts.RSS.RSSLocation.URL,
strPathName, IranianExperts.RSS.RSSFeedType.item);
grdData.DataBind();
or strPathName = "http://localhost/working_on_rss/create_rss2_sample1.aspx";
grdData.DataSource =
IranianExperts.RSS.RSSUtilities.GetRSSFeed(
IranianExperts.RSS.RSSLocation.URL,
strPathName, IranianExperts.RSS.RSSFeedType.item);
grdData.DataBind();
I wish these source codes will be useful for you. Use them and enjoy it. Best Wishes.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||