After unpublishing a post that I had accidentally published I noticed that my blog was throwing object reference not found exceptions all over the place. It turns out the Most Popular Posts Extension I installed has a minor bug in how it handles unpublished and deleted posts that were published long enough to have a counter file associated with it (the extension generates a counter file for each blog post and sticks them in the App_Data folder). Here's the fix for the TopPosts function in TopPosts.ascx.vb:
string postID = countFile.Substring(countFile.LastIndexOf('\\') + 1);
// Only add the post if it can be found and if it is still published
Post post = Post.GetPost(new Guid(postID.Remove(postID.Length - 4)));
if (post != null && post.IsPublished == true)
{
Counter temp = new Counter(postID.Remove(postID.Length - 4), Int32.Parse(fileRdr.ReadLine()));
list.Add(temp);
}
fileRdr.Close();
It's pretty straightforward. I just added a check to make sure the post exists and is still published before adding it to the list of popular posts. Otherwise, the GetPage function will throw an exception because the "post" object will be null. I hope this comes in handy for anyone else using this extension!



Thanks
Good one…I want to ask you one thing which BlogEngine.NET template are you using?
@Pankaj
No template. The blog theme was just something I threw together in my spare time.