How to customize Syndication in BlogEngine.NET

by rahul 9/1/2008 11:08:15 AM

If you are a blogger and using BlogEngine.NET, one thing is implied for sure… and that is… you like control. And more of it just makes you happier. In this post, I will explain how you can customize the output that your feed readers see in the newsreader, aka. syndication output.

Before having a look at the code, let me show you what exactly I mean…

Have a look at my reader’s snapshot. You see my signature (-Rahul), and just below that you see a link called Make a Donation. You can have as many links as you like here and if you tweak it some more, you can squeeze in some ads here as well.

image

To insert more links, you won’t have to re-compile your whole Blog application every time you make any change to the text, but to get this thing working in the first place, you’ll need to compile the application once.

Let’s get started.

Note: I am working with BlogEngine.NET 1.4.5

 image In your App_Data folder create a file called CustomText.txt and paste the text that you want to be present in all your posts. For ex.

<div class="customtext">
<br />
<a href="donate.htm">Make a Donation</a>
</div>

image Modify the following in BlogEngine.Core\SyndicationGenerator.cs

From...

//------------------------------------------------------------
//    Write required channel item elements
//------------------------------------------------------------
writer.WriteElementString("title", publishable.Title);
writer.WriteElementString("description", content);
writer.WriteElementString("link", Utils.ConvertToAbsolute(publishable.RelativeLink).ToString());

To...

            //------------------------------------------------------------
            //    Write required channel item elements
            //------------------------------------------------------------
            string fileName = System.Web.HttpRuntime.AppDomainAppPath + "\\app_data\\customtext.txt";
            System.IO.StreamReader sr = new System.IO.StreamReader(fileName);
            content = content + sr.ReadToEnd();
            sr.Dispose();
            writer.WriteElementString("title", publishable.Title);
            writer.WriteElementString("description", content);
            writer.WriteElementString("link", Utils.ConvertToAbsolute(publishable.RelativeLink).ToString());

image Now open, BlogEngine.Core\Web\Controls\PostViewBase.cs

image Modify the following

From...

// Finally we add any trailing static text.
bodyContent.Controls.Add(new LiteralControl(content.Substring(currentPosition, content.Length - currentPosition)));

To...

// Finally we add any trailing static text.
bodyContent.Controls.Add(new LiteralControl(content.Substring(currentPosition, content.Length - currentPosition)));
string fileName = Server.MapPath(BlogSettings.Instance.StorageLocation) + "customtext.txt";
System.IO.StreamReader sr = new System.IO.StreamReader(fileName);
bodyContent.Controls.Add(new LiteralControl(sr.ReadToEnd()));
sr.Dispose();

image That’s it. You’re done. Now deploy the code, and in case you want to change the text, all you need to change is that guy called CustomText.txt in your App_Data folder.

Hope this helps, Wave
Rahul


Quote of the day:
Confusion is always the most honest response. - Marty Indik


blog comments powered by Disqus

Comments

Search


Tags



Categories

Calendar

<<  March 2010  >>
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

All Items
Sign in

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2010, Rahul Soni

Powered by BlogEngine.NET 1.4.5.0