Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add status icons over file icons in Explorer, like Dropbox or SVN in .NET

I'm writing a Windows service application in C# with FileSystemWatcher.

How can I add status icons to files and folders in Windows Explorer similar to how Dropbox or SVN do it?

like image 871
spyke Avatar asked Dec 05 '11 10:12

spyke


People also ask

How do I show icons in File Explorer?

Open My Computer or File Explorer. Click View in the menu at the top of the window. If you do not see the View menu, press Alt to make it visible. Select Extra large icons, Large icons, Medium Icons, Small icons, List, Details, Tiles, or Content to change the view you want to see.

How do I customize the File Explorer icon?

Right-click the shortcut you created, click Properties, and then click Change Icon. Click the picture of the icon you would like the shortcut to use, click OK, and then click OK.

Which icon is used to explore folders and files?

You can view and organize files and folders using a built-in application known as File Explorer (called Windows Explorer in Windows 7 and earlier versions). To open File Explorer, click the File Explorer icon on the taskbar, or double-click any folder on your desktop. A new File Explorer window will appear.


1 Answers

For anyone still interessted in this question:

Here is a codeproject link which describes the process in great detail.

It uses the SharpShell library, which can also be found on nuget.

Code, from the codeproject, looks something like that:

[ComVisible(true)]
public class ReadOnlyFileIconOverlayHandler : SharpIconOverlayHandler
{
  protected override int GetPriority()
  {
    //  The read only icon overlay is very low priority.
    return 90;
  }

  protected override bool CanShowOverlay(string path, FILE_ATTRIBUTE attributes)
  {
    try
    {
      //  Get the file attributes.
      var fileAttributes = new FileInfo(path);

      //  Return true if the file is read only, meaning we'll show the overlay.
      return fileAttributes.IsReadOnly;
    }
    catch (Exception) { return false; }
  }

  protected override System.Drawing.Icon GetOverlayIcon()
  {
    //  Return the read only icon.
    return Properties.Resources.ReadOnly;
  }
}
like image 112
Firen Avatar answered Sep 22 '22 05:09

Firen