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.
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
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>
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());
Now open, BlogEngine.Core\Web\Controls\PostViewBase.cs
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();
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,
Rahul
Quote of the day: Confusion is always the most honest response. - Marty Indik