0 comments

We’ve been talking about getting ourselves a puppy for a number of years but since we had cats while we lived in Sweden, we never really looked into it seriously. But after moving back to Denmark and changing our lives around a bit, we decided that now was just about the right time to start looking around. We chose to go for a Jack Russell terrier, mostly because they’re cute but also because they are an intelligent breed of dog. This means they are easily trained and can make really good family dogs. David looked around a bit and after talking to a lady who lives in the same building as us, found his way to Kennel Hoba

We went out yesterday to look at their puppies and ended up taking home the one named Hoba’s Speedy (there’s something about breeders giving their puppies names in alphabetical order or something – and the name of the kennel is there to keep track in the breeding program).

 

Apollo1 

We decided to change his name to Apollo, and he’s now busy settling into his new home. He has already found his spot next to whoever is sitting on the couch watching TV :-)

We’ll probably set up a separate blog to post pics and stuff of our progress with him.

0 comments

I just stumbled over a funny little thing in the HTML output from the Html.CheckBox() helper method in ASP.NET MVC 1.0.

In my .ASPX file, I had defined a checkbox like this

<%=Html.CheckBox("MyCheckBox") %>

 
This resulted in the following HTML output:

<input id="MyCheckBox" name="MyCheckBox" type="checkbox" value="true" /><input name="MyCheckBox" type="hidden" value="false" /> 


A bit stumped as to why I got an extra hidden field, I decided to have a look in the ASP.NET MVC source code and found the following comment:

if (inputType == InputType.CheckBox) {
    // Render an additional <input type="hidden".../> for checkboxes. This
    // addresses scenarios where unchecked checkboxes are not sent in the request.
    // Sending a hidden input makes it possible to know that the checkbox was present
    // on the page when the request was submitted.
...

This is really quite logical. The reason it works is that the first time a browser hits an element with a value attribute, the parser will ignore all subsequent elements with the same name. This way, we’ll always get a result back to our controller containing all the checkboxes that are present on the page, no matter if they are checked or not.

0 comments

A friend of mine mailed me yesterday saying that he remembered that I had showed him a way of generating an RSS feed easily from an ASP.NET page. I pointed him at an old blog post that I wrote a couple of years back.

However, I remembered after sending him the link that I had actually re-coded that whole page to make use of a feature in the .NET library that is made for exactly the task of creating syndication feeds.

So here’s a code snippet that does basically the same thing as the old way, but does it all in C# (which means you could throw it in a HttpHandler and let it handle requests for *.rss or *.xml files :-))

 

public void ShoutBox()
{
    Response.Buffer = false;
    Response.Clear();
    Response.ContentType = "application/xml";

    using (XmlWriter writer = XmlWriter.Create(Response.OutputStream))
    {
        SyndicationFeed feed = new SyndicationFeed("mrfs.se: Shouts",
                                               "Malmö Radioflygsällskaps Shoutbox",
                                               new Uri("http://www.mrfs.se"));
        feed.Authors.Add(new SyndicationPerson("webmaster@mrfs.se", "MRFS Webmaster", "http://www.mrfs.se"));
        feed.Categories.Add(new SyndicationCategory("Shouts"));
        feed.Copyright = new TextSyndicationContent("Copyright © 2009 Malmö Radioflygsällskap");
        feed.Generator = "Graffen's RSS Generator";
        feed.Language = "se-SE";

        List<SyndicationItem> items = new List<SyndicationItem>();
        foreach (var shout in r.GetShouts(20))
        {

            SyndicationItem item = new SyndicationItem();
            item.Id = shout.ShoutDate + ":" + shout.ShoutedBy;
            item.Title = TextSyndicationContent.CreatePlaintextContent(shout.ShoutedBy);
            item.Content = TextSyndicationContent.CreateXhtmlContent(shout.ShoutText);
            item.PublishDate = shout.ShoutDate;
            item.Categories.Add(new SyndicationCategory("Shouts"));

            items.Add(item);
        }
        feed.Items = items;
        Rss20FeedFormatter rssFormatter = new Rss20FeedFormatter(feed);
        if (writer != null)
        {
            rssFormatter.WriteTo(writer);
            writer.Flush();
        }
    }
    Response.End();
}

0 comments

I’ve just spent an hour looking over our Sharepoint site at work and decided that I wanted to implement the same code syntax highlighting plugin as I use on here, namely the SyntaxHighlighter plugin.

To do this was actually pretty straightforward, once I figured it out. The following steps need to be performed on all three “views” that the blog has: Default, Post and Category. What you need to do is as follows:

  1. Put the page in Edit Mode by clicking Site Actions –> Edit Page in the top right corner
    image
  2. Click image  above the “Posts” Web Part
  3. Select image and press Add
  4. On the right side of the Web Part, click Edit and select Modify Shared Web Part
    image
  5. Click the image button
  6. Insert the following code snippet:
    <link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/2.1.364/styles/shCore.css"/>  
    <link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/2.1.364/styles/shThemeDefault.css"/>  
    <script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shCore.js"></script>  
    <script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushCSharp.js"></script>  
    <script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushXml.js"></script>  
    <script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/2.1.364/scripts/shBrushSql.js"></script>  
    <script type="text/javascript">  
        SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/2.1.364/scripts/clipboard.swf';  
        SyntaxHighlighter.all();  
    </script> 
  7. To add more brushes, simply add the references you want. To see the list, browse to http://alexgorbatchev.com/pub/sh/2.1.364/scripts/
  8. Next, in the tool panel on the right side of the page, expand the Layout section and select Hidden
    image
  9. Click OK

 

Now all you need to do is use the PreCode Pluginfor Windows Live Writer (or alternatively just use the <pre class=”brush: csharp”> … code … </pre> in the WYSIWYG editor (remember to click the Edit Html button)


image

Happy blogging :-)

0 comments

Okay, so it’s getting really annoying now. Every morning I have to spend about 30 minutes deleting comment spam from my blog. Just this morning, here’s what my GMail inbox looked like:

 blogspam

 

I’ve tried to enable the akismet extension, but something isn’t quite right – at least not when I upload my blog to my hosting provider (Surftown). When I add the extension, my extensions config page goes empty (or only shows 1 or 2 extensions – it differs). To rule out the possibility of a bug in the akismet extension, I tried adding a much simpler extension that doesn’t really do anything. Here’s the code:

using System;
using System.Web;
using BlogEngine.Core;
using BlogEngine.Core.Web;
using BlogEngine.Core.Web.Controls;
using BlogEngine.Core.Web.HttpHandlers;

[Extension("Just a test!", "0.1", "Graffen")]
public class TestExtension
{
  static TestExtension()
  {

  }
}

Before adding this extension to the app_code folder on my blog at Surftown, here’s what the extension settings page looked like:

  extensions_b4_add_new

And here’s the same list, after only adding the above file:

 extensions_after_add_new

Deleting the file again brings back all the other extensions – so it must have something to do either with the extension handler, or with a configuration issue at my hosting provider.

There’s nothing in my error log, and the application isn’t throwing any exceptions (at least none that I can see). Anyone have any ideas? Please post a comment if you do (but if your name is “payday loans” I’ll just delete your posting) I’m running BlogEngine.NET 1.5.0.7 on a shared host at Surftown Denmark.