Friday, November 18, 2011

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:

http://www.iis.net/download/FTP

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

image

(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: http://learn.iis.net/page.aspx/263/installing-and-configuring-ftp-7-on-iis-7/

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)

image

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:

https://docs.google.com/open?id=0BzvtUeIvT94wMzg1MWRjZjEtZTUyNi00YTlkLWJhMDUtYjczMTljYzdmNmYy

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

EntLib–Logging–SwitchValues

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

Value

Description

ActivityTracing

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

All

Allows all events through.

Critical

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

Error

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

Information

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

Off

Does not allow any events through.

Verbose

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

Warning

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

MSDN: http://msdn.microsoft.com/en-us/library/ff664426(v=PandP.50).aspx

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)
        {
            Console.WriteLine(instance.GetInteger());
        }

    }

    Console.ReadLine();
}

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

Monday, October 31, 2011

WP7–Hidden Wifi networks–Awesome Possum

Got to try out the new WP7 mango capability of being able to connect to hidden networks. It works. Nothing more to it. It was one of the features that I was waiting quite eagerly for.

It works…. Enuff said.

Awesome!

Saturday, October 29, 2011

WP7–NeutralResourceLanguage attribute is missing

If you get the “Neutral Resource Language” attribute is missing when uploading a XAP during app-submission, then you need to set the Neutral Language.

image

The Neutral Language setting is set via the project properties under the Assembly Information dialog.

image

Important: Once you have uploaded your app, you cannot change the Neutral Language to setting that narrows the language set. (example: if your previous version was English, then you cannot select English (United States)).

Friday, October 28, 2011

Wednesday, October 26, 2011

IIS 7–listing sites and ports used

AppCmd.exe to the rescue (c:\windows\system32\inetserv\appcmd.exe)

The command “appcmd list site” will list all the sites (and in addition will display the bindings and the ports used by the sites)

Sunday, October 23, 2011

C# debugging–an input message box

C# doesn’t have a convenient message-box that you can use for gathering user-input (which is especially useful when you are writing code for the purpose of debugging). VisualBasic has just such a form, which you can use in C#.

Add a reference to Microsoft.VisualBasic.dll

Use the following code:

Microsoft.VisualBasic.Interaction.InputBox("What would you like to do today?","To be or not to be","that is the question…");

Which creates a dialog like so:
image

MSDN: http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.interaction.inputbox.aspx