How to customize Syndication in BlogEngine.NET

by rahul 8/31/2008 11:50:15 PM

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


Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Calendar

<<  July 2009  >>
MoTuWeThFrSaSu
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

View posts in large calendar

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway. We try our best to write good code, but none of the code here is tested on Production boxes. Feel free to use the code, BUT test it before you do so (in simple words... use it at your own risk)

© Copyright 2009

Sign in