Some people have asked me how BlogEngine.NET displays a dropdown list of countries when no source XML file is present. The simple answer is that you don’t need any external list to bind to from C#, you can instead use the CultureInfo class.

Consider that you have the following dropdown list declared in an ASP.NET page:

<asp:DropDownList runat="server" ID="ddlCountry" />

Then from code-behind, call this method which binds the countries alphabetically to the dropdown:

public void BindCountries()
{
  System.Collections.Specialized.StringDictionary dic = new System.Collections.Specialized.StringDictionary();
  System.Collections.Generic.List<string> col = new System.Collections.Generic.List<string>();

  foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures))
  {
    RegionInfo ri = new RegionInfo(ci.LCID);
    if (!dic.ContainsKey(ri.EnglishName))
      dic.Add(ri.EnglishName, ri.TwoLetterISORegionName.ToLowerInvariant());

    if (!col.Contains(ri.EnglishName))
      col.Add(ri.EnglishName);
  }

  col.Sort();

  ddlCountry.Items.Add(new ListItem("[Not specified]", ""));
  foreach (string key in col)
  {
    ddlCountry.Items.Add(new ListItem(key, dic[key]));
  }

  if (ddlCountry.SelectedIndex == 0 && Request.UserLanguages != null && Request.UserLanguages[0].Length == 5)
  {
    ddlCountry.SelectedValue = Request.UserLanguages[0].Substring(3);
  }

The method first adds all the countries from the CultureInfo class to a dictionary and then sorts it alphabetically. Last, it tries to retrieve the country of the browser so it can auto-select the visitors country. There might be a prettier way to sort a dictionary, but this one works.

When Visual Studio 2005 was released together with ASP.NET 2.0, the web project model was totally changed from the ASP.NET 1.x model. It took some time for me to get used to it, and in the beginning I didn’t like it much. Apparently, I was not alone and Microsoft got a lot of mail from developers who wanted the old Web Application Project (WAP) model back. Visual Studio 2005 Service Pack 1 then reintroduced the WAP model.

I never really understood why so many people wanted the old model back, because it has some serious inconveniences. My guess is that almost all of the people who wrote Microsoft wasn’t web developers to begin with, but maybe had a past doing Windows Forms to which the WAP model bares many similarities.

No change 'n review

Old school web developers like to make a small change and then see how it looks and continue to do so an awful lot of times. The WAP model doesn’t allow you to do quick changes and review them at once. You first have to compile the entire project and that can easily take 30 seconds for larger web projects. At work, we have a web project that takes 3 minutes to build.

That quickly gets very annoying and is just a waste of time. The Web Site model does not have that problem.

No quick ‘n dirty editing

In the WAP model, if you don’t have Visual Studio you cannot change anything but the layout and that is really annoying. When I’m away from my Visual Studio and finds something I want to change, then I’m not able to. The Web Site model on the other hand allows me to change anything I want using only Notepad and the build-in FTP capabilities of IE.

Annoying deployment

The initial deployment in the WAP model is easier because there are fewer files to be FTP’ed to the remote location. But if you want to make a small change and deploy it, then you have to FTP the dll file which can be several hundred kilobytes. Now you think: how can that be a problem on your super broadband connection? Well, it can if I’m doing small changes an awful lot of times and need to upload them to review them. Then that extra 5 seconds of upload time just get on my nerves.

In the Web Site model you just upload the file you changed. That’s 2 kilobytes versus 200 kilobytes.

What I’m trying to say is, that I don’t understand the popularity of the WAP model…