namespace SyncFileIconOverlay
{
[ComVisible(true)]
public class SyncFileIconOverlay:SharpIconOverlayHandler
{
protected override int GetPriority()
{
// The read only icon overlay is very low priority
return 90;
}
public int PriorityGetter()
{
return GetPriority();
}
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 true;
}
catch (Exception)
{
return false;
}
}
public bool CanShowOverlayGetter(string path)
{
return CanShowOverlay(path, FILE_ATTRIBUTE.FILE_ATTRIBUTE_NORMAL);
}
protected override System.Drawing.Icon GetOverlayIcon()
{
// Return the read only icon
return Properties.Resources.ReadOnly;
}
public System.Drawing.Icon OverlayIconGetter()
{
return GetOverlayIcon();
}
}
}
I am using the code above which I find from https://www.codeproject.com/Articles/545781/NET-Shell-Extensions-Shell-Icon-Overlay-Handlers
this is in a Class library and I reference this dll from my winform application when I need to overlayicon I am calling PriorityGetter then check with CanShowOverlayGetter finally call the OverlayIconGetter, If the CanShowOverlay function is returning true for a file it changes overlay icon but the problem is system uses this for every file in my computer without me doing anything when i register the dll and restart the explorer changes applies, but i want to check and change the icon overlay from a winform project that uploads and downloads files i want make icon overlay on those files that comes dynamically from the program. Do you guys have any idea how can i achieve this thanks!!!
You need to the some work before your icon overlay works because of the limit. You can check it here Making Icon Overlays Appear In Windows 7 and Windows 10.
...have a hard limit of 15 overlays. There’s a list in the registry, and no matter how many apps install overlays, only the first 15 are used. The rest are ignored.
Update 1
I couldn't find a better way to do it via file. But this sample will show overlay icon on specific folder.
Step 1: Set a file marker that can be hidden. In my sample i have .marker
it's just a blank file.
Step 2: Your overlay icon handler.
[ComVisible(true)]
public class FileValidIconOverlayHandler : SharpIconOverlayHandler
{
protected override int GetPriority()
{
return 10;
}
protected override bool CanShowOverlay(string path, FILE_ATTRIBUTE attributes)
{
var file = new FileInfo(path);
var hasFileMarker = file.Directory.GetFiles(".marker").Length > 0;
var isNotFileMarker = file.Name != ".marker";
var isNotDirectory = !file.Attributes.HasFlag(FileAttributes.Directory);
return hasFileMarker && isNotFileMarker && isNotDirectory;
}
protected override System.Drawing.Icon GetOverlayIcon()
{
return Properties.Resources.Valid;
}
}