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

前端 未结 3 1239
闹比i
闹比i 2020-12-24 15:24

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

3条回答
  •  Happy的楠姐
    2020-12-24 16:12

    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;
      }
    }
    

提交回复
热议问题