UPDATE: Added support for importing tracked forums and topics.

I'm in the process of converting my forums from Community Server to AspNetForum. While CS may support every single feature under the sun, its very big and unwieldly to work with. The more recent 2007 and 2008 versions are better, but still behemoth. I just want to drop in one simple forum with a couple subgroups, not host a million forums and blogs on my site. For this, AspNetForum fits the bill exactly.

There's no official importer for Community Server to AspNetForum, so I wrote my own. It turns out to be fairly simple. Just a SQL script will do it. Here are the steps the script goes through:

  1. Import the ASP.NET application, user, and membership tables
  2. Create the AspNetForum single sign-on linkages in its ForumUsers table
  3. Import the groups, forums, topics, and messages

I packaged all this up into a SQL script that handles the whole process end to end. Just edit it to point to your database and forums and it will do the rest. It assumes the following:

  • You've created and set up an AspNetForum database
  • You've created the ASP.NET user and membership tables in the AspNetForum database
  • The AspNetForum and ASP.NET user and membership tables are new and empty

This script will import everything with the same ID values from Community Server, making mapping or redirecting easy.

To use the script in SQL Management Studio, do the following steps:

  1. Open the script (Import.sql) and connect it to your AspNetForum database
  2. Execute a search and replace operation that replaces "CSDatabaseName" with the name of your Community Server database
  3. Set the @applicationId variable to the ApplicationId matching your Community Server instance in the aspnet_Applications table in your CS database
  4. Set the @groupId variable to the GroupId of the forum group to import from the cs_Groups table
  5. Execute the script

Download the script and get importing! – CommunityServer2AspNetForumsImport.zip

As I develop, I often have images that are bitmaps or other formats that I want to convert to transparent .png's for use in a website. I whipped up a little app that does a bmp2png conversion, using the RegistryHelper class to hook the right click context menu.

Converting an image in .NET is very straightforward, as long as you are doing a conversion from and to a .NET supported image format. Just load the image using the System.Drawing classes, and then save it as the image format you want. Making a color transparent is easy as well -- call the Bitmap.MakeTransparent method and pass in the color to make transparent.

Here's a snippet of the code I used to do the conversion and transparency settings:

using (Stream s = File.OpenRead(srcFileName))
using (Bitmap src = Image.FromStream(s, false, false) as Bitmap)
{
src.MakeTransparent(TransparentColor);
src.Save(destFileName, ImageFormat.Png);
}

The transparent color by default is RGB 0, 255, 128. You can change it using a appSettings key in the app.config as follows:

<add key="transparentColor" value="0, 255, 128" />

The app registers the context menu extension automatically when you run it with no arguments, and thereafter .bmp files will have a "Convert to png" right click context menu item. It would be very simple to add additional from and to formats to this code. Let me know if this is something you'd be interested in and I'll add it.

NOTE: To register the extension, administrative permissions are required.

Bmp2Png executable
Bmp2Png source

For several programs, I've wanted to be able to add a shell context menu item for a file that runs an exe. After some research, I came up with the following information. This menu is controlled by certain registry entries under the HKCR (Classes Root) entry. In HKCR, there are two relevant entries for each file extension: the actual extension, and the handler for that extension. For .bmp, for example, the extension key is as follows:

The key part of the extension key is the default string value that points to the handler for this extension, in this case Paint.Picture. Here's the handler:

To add a new context menu item, simply add a new key to the shell subkey of the handler key. Name it whatever you want. The default string value for the key will be the caption of the menu item. To specify the command to run, add a command subkey to your menu item key. The default string value of this key should be the path to your application. You can append "%1" to pass the filename of the file to your app.

I've written a registry helper class that encapsulates all of this, allowing you to create a handler with just one line of code. You can call it as follows:

RegistryHelper.RegisterHandler(".ext","commandname","caption",true);

Where:

  • ".ext" is the extension you want to add a context menu to
  • "commandname" is the name of the command
  • "caption" is the caption to display in the context menu
  • the boolean in the last parameter determines whether to create a system-wide context menu extension, or to register it for just the current user

This overload will determine what the path is to the currently running assembly, or you can use one of the other overloads that allows you to specify the path.

RegistryHelper.cs