Wednesday, January 6, 2010

How to show code and not have Blogger interpret it

I had issues with my previous blog and getting both the HTML and the code behind to show correctly (and nicely).

I was able to get the code behind to come out nice and color coded by downloading and using Copy Source As HTML

That covered the code behind, but was not helpful for the HTML. After a bit of research I found that if I use character entities, I am able to display my code (although it is not color coded).

Example: The code used to make this statement bold
is:

<b>The code used to make this statement bold is </b>

To do this, you will need this table converter of the most common conversions:


So, everywhere there is a Less Than symbol, you need to replace it with its equivalent entity name. You can find a complete listing of entity names at the w3schools web page.

You can do a find and replace in Notepad, or you can paste your code into This Web Page and it will convert it all for you. There is a slight usage disclaimer on the bottom of the page, but I read that after I used it.

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!!