Recent comments macro for DasBlog
Tuesday, February 17, 2009 9:25:05 AM (GMT Standard Time, UTC+00:00)
One of the issues I had with John Forsythe's Recent Comments macro for DasBlog was that the dasBlog recent comments weren't ordered by date (descending). I found that as people commented on older posts they were getting buried which irritated me as many were very still valid comments.
The fix was actually fairly simple, it was just a matter of adding a sort and thanks to Lamba expressions, this is something we can do fairly simply. If you want to add recent comments to your dasBlog installation, use the following macro:
Recent Comments Macro
public virtual Control RecentComments(
int count,
int adminComments,
int trimTitle,
int trimContent,
int trimAuthor,
bool showTitle,
bool showCommentText,
bool showCommentCount)
{...} 
{
int commentsToShow;
int totalComments;

CommentCollection allComments =
this.requestPage.DataService.GetAllComments();

totalComments = allComments.Count;
//Sort the comments in date order (descending) 
allComments.Sort((c1, c2) => c1.CreatedUtc.CompareTo(c2.CreatedUtc));
if (!
this.requestPage.HideAdminTools && SiteSecurity.IsInRole(
"admin"))

commentsToShow = totalComments - adminComments;
else 
commentsToShow = totalComments - count;
if (commentsToShow <
0)

commentsToShow =
0;

StringBuilder sb =
new StringBuilder();

sb.AppendLine(
"<div class=\"recentComments\">");
if (showCommentCount)

sb.AppendFormat(
"<div class=\"totalComments\">Total Comments: {0}</div>", totalComments);

sb.AppendLine(
"<ul class=\"comments\">");
Loop through the comments
#region Loop through the comments
for (
int i = totalComments -
1; i >= commentsToShow; i--)
{...} 
{

Comment current = allComments[i];
bool showComment;
if (!current.IsPublic || (current.SpamState == SpamState.Spam))
{...} 
{
if (!
this.requestPage.HideAdminTools && SiteSecurity.IsInRole(
"admin"))
{...}
else
{...} 
{

showComment =
false;
if (commentsToShow >
0)

commentsToShow--;

}

}
else
{...}
if (showComment)
{...} 
{
if ((current.SpamState == SpamState.Spam))

sb.Append(
"<li class=\"spam\">");
else if (!current.IsPublic)

sb.Append(
"<li class=\"hidden\">");
else 
sb.Append(
"<li>");
string link =
String.Format(
"{0}{1}{2}", SiteUtilities.GetCommentViewUrl(current.TargetEntryId),
"#", current.EntryId);
string title = current.TargetTitle;
string desc = current.Content;
string author = current.Author;
if (showTitle)
{...} 
{

sb.AppendFormat(
"<div class=\"recent{0}CommentsTitle\"><a href=\"{1}\">",

current.SpamState,

link

);
if ((title.Length > trimTitle) && (trimTitle >
0))

sb.AppendFormat(
"RE: {0}...", title.Substring(
0, trimTitle));
else 
sb.AppendFormat(
"RE: {0}", title);

sb.Append(
"</a></div>");

}
if (showCommentText)
{...} 
{

sb.AppendFormat(
"<div class=\"recentCommentsContent\"><a href=\"{0}\">",

link

);
if ((desc.Length > trimContent) && (trimContent >
0))
{...} 
{

sb.Append(desc.Substring(
0, trimContent));

sb.Append(
"...");

}
else
{...}

sb.Append(
"</a></div>");

}

sb.Append(
"<div class=\"recentCommentsAuthor\">");
if ((author.Length > trimAuthor) && (trimAuthor >
0))
{...} 
{
int num3 = (trimAuthor > author.Length) ? author.Length : trimAuthor;

sb.Append(
"by " + author.Substring(
0, num3));

sb.Append(
"...");

}
else
{...} 
{

sb.Append(
"by " + author);

}

sb.Append(
"</div></li>");

}

}
#endregion

sb.AppendLine(
"</ul>");

sb.AppendLine(
"</div>");
return new LiteralControl(sb.ToString());

}
I've since been working on extending it further so you can add a "All Comments" link which I'll post up later as it needs a little more work :)
If you want this wrapped up as a DLL let me know and I'll upload it.
Update 26th Feb 2009: You can download the dll here (it's also got a few other things in there if you want to look around).
Update 27th Feb 2009: I noticed that the above code was messing up everynow and again so I've updated it to use Linq instead which seems to work well. I've updated the DLL but not the source yet.
Can Twitter be a bad thing for your business?
Monday, February 09, 2009 10:26:45 PM (GMT Standard Time, UTC+00:00)
There's going to be a series of articles shortly that go into my attempts of using social networking to build your business but I thought I'd get this one out into the blogosphere first.
What with the recent onslaught of "celebrities" onto Twitter such as Stephen Fry (who incidentally p'd a lot of people off the other day while over-posting), Chris Moyles and David Allen to mention a few, it got me thinking whether Twitter can actually be a negative thing for you and/or your business. I'm not referring to the tremendous time you lose reading and responding to the numerous posts (Tweets) but more about the transparency issues you'll run into.
Those of you who know me in person know that I don't tend to bite my tongue (not always a good thing I can tell you!) and instead tend to speak openly and honestly regardless of the situation, so for me I don't really worry about what I Tweet, IM, e-mail or SMS as it's usually saying the same thing (unless I'm tired and losing my mind!). I have however noticed that's not true for everyone.
For me, Twitter, MSN and these other social-status update services such as Facebook bring a whole new layer of complexity to those who want to "skive" -who hasn't seen the notorious Kyle Doyle email. It's not so much full on lies like Kyle's that I'm referring to but more the little ones like saying you couldn't complete some work because of xyz and then having posted a message on Twitter along the lines of "sod this I'm off to the pub". When your employer (or even friend) see's that, if it doesn't immediately annoy them, it will certainly plant the seed of doubt in their mind.
I've been seeing this "phenomenon" for a while, it started with MSN status updates, then Facebook and now the worst of them all -Twitter. For goodness sake, just be honest, if you lie these days you're so much more likely to be caught out and that really can ruin your reputation -or at least lose you business.
Answer machine messages
Tuesday, January 27, 2009 6:19:22 PM (GMT Standard Time, UTC+00:00)
Listening to Stacey update our answer machine messages today and Darren Ferguson posting on Twitter asking how to write project synopsis' got me thinking about KISS and that people knew what an answer machine was there for now and they didn't need a load of drivel about the fact that we're not here, leave a message, that we'll get back to them as soon as possible, they're just waiting for the beep (a lot of the time these days the provider then explains what to do to re-record your message etc -incidentally, have you ever used that? I've not) so why get in their way.
Although it's not something we've done yet, I'm thinking of changing the company message to something like "You've got through to The Site Doctor, we're not in, leave us a message or email" and that's it. Short, sweet and simple. I'm tempted to go as far as "The Site Doctor is closed, here's the beep" but that might be too blunt.
Why should they differ? People know what they're there for, get them straight to the point and don't fluff around it. BTW if you're interested to know what I think makes a good portfolio write up, again KISS and say as much as possible while writing as little as possible -the client doesn't generally care what technology you're using (9/10 they'll say they want PHP when they meant ASP.Net FWIW) as that's generally gobeldygook to them anyway.
It's also important to keep it as short as possible (unless you're not aiming at them reading it i.e. SEO). The readers not interested in how much trouble you went to, just make sure the following is mentioned (if it's true)!
- How they found you, this can be subtly e.g. "Acme Corp contacted The Site Doctor to." or "Acme Corp was referred to The Site Doctor" -says all it needs no?
- Overview what the general spec was e.g. "We were commissioned to do ABC"
- Overview any successes that you had e.g. "We achieved everything Acme Corp asked of us within the timescales and budgets outlined"
- Without getting too techy, overview how it works and what they can do with it
- Use your company name once or twice but not every time, it's not necessary
As I said, our portfolio doesn't always follow this at the moment but we're working on it. A better example is our paper brochure where we only had 50-100 words per project.
New Years Resolutions and Getting rid of deadwood
Sunday, January 25, 2009 1:37:01 PM (GMT Standard Time, UTC+00:00)
Have you made any New Year's resolutions this year? -That's a question I'm sure you've been asked a dozen times already this year. New Year's resolutions have always amused me, the thought that people wait around for months to make (often) big changes in their life has baffled me.
If you run a business you'll know that it's important to review, assess and action a huge number of factors pretty much on a daily basis, if you don't, your business is likely to be slow to react to changes within your market place and so struggle.
I think its human nature to have a point to focus on whether it's the beginning of a new year, a holiday, even the recession but why wait until the end of the week? Or even better when you identify a problem? Surely that would be better?
That said the New Year and the recession are giving companies (including The Site Doctor) the perfect opportunity to clean out the deadwood within their businesses and reassess everyone's roles.
What do you do? Do you review weekly, monthly or annually? At The Site Doctor we have weekly meetings to review the previous week's successes, failures, evaluate next week's goals and more importantly to identify areas that require attention. This doesn't need to take long but it allows you to react quickly to emerging issues and limit the impact it could have.
If you're being hit by the recession (my sympathies go out to you if they are affecting your business) then you should be asking yourself "If I had reviewed our current position sooner, would I have been able to spot any warning signs?". I rather suspect if you are on top of your business you would have been able to.
If I were you, I'd look to make my New Year's resolution this year to not need one next year because you action the issues as soon as they arise.
Umbraco tip of the day –sort your document types
Wednesday, January 21, 2009 7:59:39 PM (GMT Standard Time, UTC+00:00)
I thought I'd share this as it's something I've been thinking about trying for a while. Umbraco is great but sometimes you want the default document selected when creating a page to be one that isn't the alphabetically first one.
To work around this I tend to prefix the important Umbraco document types with a symbol (or you could use 1. etc I guess) but if instead you use a space (" ") before the name of your document type, Umbraco will place it at the top of the list for you.

The nice thing to note here is that they obviously trim the name first so it just appears as "Text Page" rather than " Text Page".
I found this out on our latest site which is just about to go live: www.nhshistopathology.net -check it out and let me know what you think.
Enjoy!
Feedstats dropped by half overnight?
Tuesday, January 20, 2009 1:22:45 PM (GMT Standard Time, UTC+00:00)
This was an interesting one, I've had about 42 subscribers for months (or there abouts) and then suddenly on Friday I lost nearly half.
I know they're not big numbers but I wonder if Feedburner have noticed a glitch in their code.

Another Google feature
Monday, January 19, 2009 7:46:56 PM (GMT Standard Time, UTC+00:00)
As I don't follow football I'm probably slow to pick this one up but thought I'd share it, when Googling "Newcastle" I got last/next fixture results so I thought I'd try it for West Brom:
Pretty neat. I wonder when it'll start showing results from the marathon canoeing ;)
ASP.Net Profiles - Value cannot be null.Parameter name: type
Sunday, January 18, 2009 6:49:53 PM (GMT Standard Time, UTC+00:00)
This is the second time I've come across the error "Value cannot be null.Parameter name: type" when using ASP.Net Membership Profiles.
Profiles are great, they allow you to store little pieces of information e.g. their user id (an integer reference to your database) on the user against their User object. You can then use that as a property of the User which can get you out of a bind or two.
Since switching to Web Deployment projects to get around a few issues with multiple environment configuration switching however I started to get "Value cannot be null.Parameter name: type". After a little Googling around I found that it relates to the setting "Treat as library component (remove the App_Code.compiled file)" setting under the property pages.
Un-checking the box sorts all your woes :)
