I recently moved from a home-grown blogging engine to .text (dottext), mainly because of the ‘blog anywhere’ web admin interface, and comment support. Because my old site was written by myself, it had in it most of the things I wanted. The released of .text contains many skins, but none of them were really what I was after, so I have started dabbling with skin design. You are probably reading this article on a page with my own skin. When you create your own skin or edit another you can add your own controls to the page.
Some of the user controls that I had written for my old site allowed me to syndicate some of my friends’ blogs. I wanted this functionality in my .text site, so I went hunting. As usual, it was Scott Mitchell who showed me the way, with his RSSFeed control. I have implemented a version of this in my site and I am happy with the result. See the code posted below.
Disclaimer: I am not a programmer, I am an infrastructure geek who dabbles. The below code has no error-handling, so if something goes wrong with the feed it will break your whole site. I tried to put in error handling but it didn’t work. I hope a real programmer reads this and tells me what to do.
Because I don’t want to potentially show a 2000 word post in the 200px wide box allocated, I have written a function to shorten the post to 49 characters.
<%@ Control Language="c#" ClassName="darrynRSS" Inherits="Dottext.Web.UI.Controls.BaseControl" targetschema="http://schemas.microsoft.com/intellisense/ie5” %>
<%@ Register TagPrefix="skm" Namespace="skmRss" Assembly="skmRss" %>
private void Page_Load(object sender, System.EventArgs e)
{
RssFeed1.DataSource = "https://www.darryn.net/rss.aspx/";
RssFeed1.DataBind();
}
public string shorten(String input)
{
string shortbody = "";
string [] a; // array of strings are square-bracketed
int j; // int not Integer
if(input == null)
{ // real quick error check to stop more serious errors
return "";
}
a = input.Split(" ".ToCharArray()); // get our array of strings
int maxnum = a.GetUpperBound(0) ; // We actually know that 49's max from above
if(maxnum > 49)
{
for(int x = 0; x <= 49; x++)
{ // I love C style loops
shortbody += " " + a[x];
}
shortbody += "…";
}
else
{
return input; // can return any string - not sure if using the function name as the string is "done" in C#
}
return shortbody;
}
DarrynBlog
<%# shorten(Container.DataItem.Description) %>
Please provide feedback below if you have a better solution, or for whatever reason.
How are you getting this into your skin? Can you post the code you used, I tried adding it to a skin but was getting an error about resource not found… I’ll try to play with it more later, no more time to work on it this morning.
Chris:
I didn’t mention it in the post (d’oh) but you need to put the skmRSS.dll into your bin directory. It will Just Know.
Darryn, I don´t understand your website at all! Put something on it that a non computer geek can understand.
Love Mel