I was installing the Simple Counter Extension for BlogEngine.Net (created by Al Nyveldt) today when I ran into a slight glitch. My download counts were being tallied properly in the downloadcounts.xml file. However, when I logged in to check my download counts on each link they all said “0”.

That couldn’t be right so I refreshed my cache and still nothing. The problem was that the string in the downloadcounts.xml file was not matching the string from the generated html.

Here are the two strings:

downloadcounts.xml

   1: <files> 
   2:     <file count="1">2009/6/facePLANT.zip</file> 
   3: </files>

Genderated HTML

   1: <a href="/file.axd?file=2009%2f6%2ffacePLANT.zip">

The solution was to add one line code to the SimpleDownloadCounter.cs file. Just open the file and update the UpdateDisplay method:

   1: private string UpdateDisplay(string body)
   2:   {
   3:     if (body.Contains("file.axd?file="))
   4:     {
   5:       int pos = body.IndexOf("file.axd?file=");
   6:       while (pos > 0)
   7:       {
   8:         pos = pos + 14;
   9:         string filename = body.Substring(pos, body.IndexOf("\"", pos) - pos);
  10:         filename = Uri.UnescapeDataString(filename);
  11:         int count = GetFileCount(filename);
  12:         int linkTextEnds = body.IndexOf("</a>", pos);
  13:         body = body.Insert(linkTextEnds, " [Downloads: " + count.ToString() + "]");
  14:         pos = body.IndexOf("file.axd?file=", pos);
  15:       }
  16:     }
  17:     return body;
  18:   }

I added line 10:

   1: filename = Uri.UnescapeDataString(filename);

 

This will remove the URL Encoding from the HTML link before it tries to look it up in the xml file. Now the strings match and the counter works as intended.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkListFacebookMySpaceTwitter

Tags:

So you want to edit your blog straight from your desktop? There’s a nifty FREE program out there from Microsoft; Windows Live Writer. Here are our installation specs:

  1. BlogEngine.NET 1.5 (Ours is setup to use SQL Server)
  2. Windows Live Writer 2009

Now that you have those two installed, setup is a snap. There are just a few steps to configure Windows Live Writer. First you have to select the blog service.

Since we are using BlogEngine.NET (MetaWeblog API) we will select “Other blog service”.

Next provide your blog URL and login credentials.

If you have your blog installed in a sub-directory of your website you will use the sub-directory location:

http://www.mysite.com/blog

Otherwise, if your blog is installed at the root, you will use the root url:

http://www.myblog.com or http://blog.mysite.com

BlogEngine.NET 1.5 supports Really Simple Discovery (RSD), so windows live writer will automatically determine the correct settings to post, edit, and delete posts. Finish the setup by naming your blog in Windows Live writer, and then you’re good to post until your heart is content.

Another great feature of Windows Live Writer is the use of plug-ins. One useful plug-in I’ve found is the Twitter Notify plug-in. This will allow you configure and post twitter updates for your blog posts.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkListFacebookMySpaceTwitter

Tags: , ,