Tuesday, January 5, 2010

System.ServiceModel.Syndication

After posting my last blog about the ultra-sweet rss toolkit I found, I was informed that with the release of .Net Framework 3.5, they included that feature. After a bit of research of System.ServiceModel.Syndication namespace, I took the same project that I used the toolkit on and applied some .Net 3.5 to it.

The Results: It was actually easier to code than the toolkit.

How to use:
1. add reference to System.ServiceModel.Web assembly
2. Choose where you want your rss to display. Add a Label and a DataList.
3. Here is the template for the markup


<asp:DataList ID="DataList1" runat="server" Height="445px" Width="215px">
<ItemTemplate>
<asp:HyperLink ID="Hyperlink1" runat="server"
Text='<%# Eval("Title.Text") %>'
Font-Bold="true"
NavigateUrl='<%# Eval("Links[0].Uri.AbsoluteUri") %>'>
</asp:HyperLink>
<br />

<br />
</ItemTemplate>
</asp:DataList>4. Place the following in the Page_Load

32 XmlReader reader = XmlReader.Create

33 ("http://URLofYourBlog");

34

35 Rss20FeedFormatter formatter =

36 new Rss20FeedFormatter();

37 formatter.ReadFrom(reader);

38 reader.Close();

39

40 DataList1.DataSource = formatter.Feed.Items;

41 DataList1.DataBind();



5. I was getting a Dtd security error and fixed it by adding

27 XmlReaderSettings settings = new XmlReaderSettings();

28 settings.ProhibitDtd = false;



To the beginning of the event holder.

6. Good luck debugging for your specific project!!

No comments:

Post a Comment