Click here to Skip to main content
15,885,278 members
Articles / Desktop Programming / Win32

.NET Shell Extensions - Shell Icon Overlay Handlers

Rate me:
Please Sign up or sign in to vote.
5.00/5 (32 votes)
14 Sep 2013CPOL7 min read 185.5K   6.5K   83  
Create Shell Icon Overlay Handlers using .NET!
using System;
using System.ComponentModel.Composition.Hosting;
using System.IO;
using System.Windows.Forms;
using SharpShell;
using SharpShell.SharpPropertySheet;

namespace ServerManager
{
    public static class ServerManagerApi
    {
        public static ServerEntry LoadServer(string path)
        {
            try
            {
                //  Create a server entry for the server.
                var serverEntry = new ServerEntry();

                //  Set the data.
                serverEntry.ServerName = Path.GetFileNameWithoutExtension(path);
                serverEntry.ServerPath = path;

                //  Create an assembly catalog for the assembly and a container from it.
                var catalog = new AssemblyCatalog(Path.GetFullPath(path));
                var container = new CompositionContainer(catalog);

                //  Get the exported server.
                var server = container.GetExport<ISharpShellServer>().Value;

                serverEntry.ServerType = server.ServerType;
                serverEntry.ClassId = server.GetType().GUID;
                serverEntry.Server = server;

                return serverEntry;
            }
            catch (Exception)
            {
                //  It's almost certainly not a COM server.
                MessageBox.Show("The file '" + Path.GetFileName(path) + "' is not a SharpShell Server.", "Warning");
                return null;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United Kingdom United Kingdom
Follow my blog at www.dwmkerr.com and find out about my charity at www.childrenshomesnepal.org.

Comments and Discussions