Monday, January 07, 2013

Pointy, Sharp Shell Extensions with SharpShell and the ".NET Shell Extensions - Shell Context Menus" tutorial

CodeProject - .NET Shell Extensions - Shell Context Menus

Introduction 

Until .NET 4.0 it was impossible to reliably create Windows Shell Extensions using .NET code. With improvements to the framework, it is now possible to use .NET to create these extensions. In this article, I'll show you how to quickly create Shell Context Menus as a C# class library.

This article is the first part in a larger series on creating Shell Extensions using .NET 4.0.  

What Are Shell Context Menus?

Shell Context Menus are COM servers that are registered in the system that allow the context menus of shell objects to be extended. This could be the context menu for a specific file type, such as *.txt files, file classes such as 'text files', drives, folders and more. The context menus can be used to provide advanced functionality that can be accessed quickly through Windows Explorer.

Getting Started

There's a lot of work involved in setting up Shell Extensions. Specific COM interfaces have to be implemented, servers must be built, the registry must be updated in a variety of ways. We're going to use a library I have developed called 'SharpShell' to do all of the hard work - leaving us with the task of creating a lightweight class library that contains our extension class.

Our Goal

The code below creates a Shell Extension that allows you to count the lines in any text file by right clicking on it and choosing 'Count Lines'. For the rest of the article I'll show you how to create a library like this. The code is shown first because I want to highlight how straightforward writing these libraries is when using SharpShell.

...

image

..."

SharpShell

SharpShell is a .NET framework that allows you to create Windows Shell Extensions quickly, using C# or Visual Basic.

Can you use the .NET Framework to write Shell Extensions? This topic is discussed in the documentation page Managed Shell Extensions.

SharpShell - Can you use the CLR for Shell Extensions?

SNAGHTMLb175c48

Been a long time since I've blogged about create Shell Extensions with .Net. And while the Windows/File Explorer might (might) be on the way out, we've got the better part of a decade where it will still be a key UI, so investing in creating your on Shell Extensions could still make a good deal of sense.

As a LOB dev, I find the thought of using them in our company interesting.... um...

2 comments:

TravisQuinn said...

This is something nice information.because i never heard about shell extension.with we can add bitmap icons in that context menus?.

Greg said...

Yes. That's one of the things this projects shows...