Monday, November 21, 2011

Shape Catcher–Unicode character recognition

Came across ShapeCatcher, a useful site that allows you to draw a shape and it suggests different unicode characters that match that shape. Definitely beats looking through Window’s CharacterMap looking for that font that looks like a clock.



Or searching for the peace symbol:


Friday, November 18, 2011

Setting up FTP under Windows Server 2008 R2 with user-isolation

In Windows Server 2008 R2. (Important these are not steps for a production environment. Just for setting up a test FTP server.)
In Server Manager:
Under Roles, click Add Role
    install FTP
        Under roles - add Web Server (IIS)
            Under role services select FTP Server
        Complete the installation
In IIS: Create a FTP Site:  
    Right click on Sites and select Add FTP Site
        Name it: Whatever you like
        Path: C:\inetpub\ftproot
    Bindings and SSL Settings
        Select No SSL

    Authentication information
        Select Basic authentication
            Select Allow access to "All users" with Read and Write permissions
    Finish the FTP creation wizard
Under settings for the FTP site (in IIS)
    Select FTP User Isolation
        Select "User name directory (disable global virtual directories)"
Create local user accounts (this is how users get access to the FTP site (or at least one way how you can provide access to your ftp site)). (example: create a local account named FtpUser1)
Create a group called FTPUsers and add user accounts created above to the group. (it makes it easier to provide access to folders as shown in the next step).
Provide the group you created in the above step (FTPUsers) modify priviledges on C:\inetpub\ftproot
Next create a sub-folder called LocalUser (C:\inetpub\ftproot\LocalUser). (important to name it exactly that).  
Create a folders for each of the user accounts you created above (eg: if you created an account call FtpUser1, create a folder under LocalUser called FtpUser1).

Test access to your FTP site via your favorite FTP client. If you did everything correctly, you should have a valid FTP site with an account setup.

FTP 7.5 on Windows Server 2008 R2

If you search for enabling FTP on Windows Server 2008, you most often get redirected to the following site:

And if you download that FTP7.5 installer referenced on that page and try and run it, you get the following error:


(this version of the operating system is not supported. FTP Service for IIS 7.0 can be installed only on Windows Server 2008).

Turns out that, for Windows Server 2008 R2, you don’t need to download a separate installer. You just need to enable the FTP role. (This is because on Windows Server 2008 R2, you get IIS 7.5 and not IIS 7.0).

More info:

Wednesday, November 16, 2011

Powershell–Run script via context menu

I wanted the ability to right click on a PS1 file and then execute a powershell script. (A “run powershell script” from Context-Menu option)


So here is how you can do it:

Copy the following text into a text file and save it:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\Shell\Run with powershell]

[HKEY_CLASSES_ROOT\*\Shell\Run with powershell\command]
@="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit &'%1'"

Save the file and rename it to have an extension “.reg”. Now double click the file and you will have a context menu called “Run with powershell”

To make life easier you can download my version of the file from:

Monday, November 14, 2011

SqlBulkCopy error: given value cannot be converted to type xxxx

If you get the following error when using SqlBulkCopy: “The given value of type String from the data source cannot be converted to type int of the specified target column.”

Then check for 2 things:

Make sure that you are not setting more characters than what is allowed for a field (i.e., column allows only 5 characters and you set the column to 6 characters).

If you are not setting all the columns, then make sure you use the “SqlBulkCopyColumnMapping”, to setup the mapping (especially true, when you are inserting rows and you are not setting the primary key value as its setup to be an identity column).

Thursday, November 03, 2011


Here are the list of values that you can use for the SwitchValue for the configuration of the logging block in Enterprise Library.




Allows the Stop, Start, Suspend, Transfer, and Resume events through.


Allows all events through.


Allows only Critical events through. A critical event is a fatal error or application crash.


Allows Critical and Error events through. An Error event is a recoverable error.


Allows Critical, Error, Warning, and Information events through. An information event is an informational message.


Does not allow any events through.


Allows Critical, Error, Warning, Information, and Verbose events through. A Verbose event is a debugging trace.


Allows Critical, Error, and Warning events through. A Warning event can indicate both critical and non-critical issues.


Wednesday, November 02, 2011

C#–Loading dlls at runtime and finding classes that implement an interface

Given: An interface that you have defined:

public interface IMyPluginInterface
    int GetInteger();

When: Your application runs

Then: It should load dlls at run time and call GetInteger on all those classes that implement the interface IMyPluginInterface

Solution: Here is how you can do that:

static void Main(string[] args)
    //find some dlls at runtime
    string[] dlls = Directory.GetFiles(Environment.CurrentDirectory, "MyPlugin*.dll");

    //loop through the found dlls and load them
    foreach (string dll in dlls)
        System.Reflection.Assembly plugin = System.Reflection.Assembly.LoadFile(dll);
        //now find the classes that implement the interface IMyPluginInterface and get an object of that type
        var instances = from t in plugin.GetTypes()
                        where t.GetInterfaces().Contains(typeof(IMyPluginInterface))
                                 && t.GetConstructor(Type.EmptyTypes) != null
                        select Activator.CreateInstance(t) as IMyPluginInterface;

        //now call the GetInteger method defined by the interface
        foreach (var instance in instances)



public class MyPlugin1 : IMyPluginInterface
    public int GetInteger()
        return 1;