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:

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

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

    ReplyDelete

NOTE: Anonymous Commenting has been turned off for a while... The comment spammers are just killing me...

ALL comments are moderated. I will review every comment before it will appear on the blog.

Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...

I reserve, and will use, the right to not approve ANY comment for ANY reason. I will not usually, but if it's off topic, spam (or even close to spam-like), inflammatory, mean, etc, etc, well... then...

Please see my comment policy for more information if you are interested.

Thanks,
Greg

PS. I am proactively moderating comments. Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...