Click or drag to resize

IFileSystemItemGetThumbnailAsync Method

IT Hit User File System
Called when thumbnail is requested by the platform.

Namespace:  ITHit.FileSystem
Assembly:  ITHit.FileSystem (in ITHit.FileSystem.dll) Version: 8.3.27213.0
Syntax
Task<byte[]> GetThumbnailAsync(
	uint size,
	IOperationContext operationContext
)

Parameters

size
Type: SystemUInt32
Thumbnail size in pixels.
operationContext
Type: ITHit.FileSystemIOperationContext
Provides information about the environment.

Return Value

Type: TaskByte
Thumbnail bitmap or null if no thumbnail should be displayed for this item.
Exceptions
ExceptionCondition
NotImplementedExceptionIf no thumbnail should be displayed.
Remarks

To show thumbnails in your virtual drive on Windows platform follow these steps:

  1. Derive your class from one of the [!:ThumbnailProviderHandlerBase] class descendants. Add the GuidAttribute, ProgIdAttribute and ComVisibleAttribute attributes to your class. You do not need to implement any methods in your class.
  2. Add the desktop3:ThumbnailProviderHandler tag to your Package.appxmanifest (in case of packaged app) or appxmanifest.xml (in case of a sparse package) that references your class. Alternativly you can register your class as a COM component using regsvr32 or any other method.
  3. Implement the GetThumbnailAsync(UInt32, IOperationContext) method to return the thumbnail bitmap data.

Thumbnails functionality does NOT require package or application identity.

Examples

The code below is part of 'WebDAVDrive' C# sample provided with the SDK.

C#
public async Task<byte[]> GetThumbnailAsync(uint size, IOperationContext operationContext)
{
    byte[] thumbnail = null;

    string[] exts = Settings.RequestThumbnailsFor.Trim().Split("|");
    string ext = System.IO.Path.GetExtension(UserFileSystemPath).TrimStart('.');

    if (exts.Any(ext.Equals) || exts.Any("*".Equals))
    {
        string ThumbnailGeneratorUrl = Settings.ThumbnailGeneratorUrl.Replace("{thumbnail width}", size.ToString()).Replace("{thumbnail height}", size.ToString());
        string filePathRemote = ThumbnailGeneratorUrl.Replace("{path to file}", Engine.Mapping.MapPath(UserFileSystemPath));

        try
        {
            using (IDownloadResponse response = await Dav.DownloadAsync(new Uri(filePathRemote)))
            {
                using (Stream stream = await response.GetResponseStreamAsync())
                {
                    thumbnail = await StreamToByteArrayAsync(stream);
                }
            }
        }
        catch (System.Net.WebException we)
        {
            Logger.LogMessage(we.Message, UserFileSystemPath);
        }
        catch (Exception e)
        {
            Logger.LogError($"Failed to load thumbnail {size}px", UserFileSystemPath, null, e, operationContext);
        }
    }

    string thumbnailResult = thumbnail != null ? "Success" : "Not Impl";
    Logger.LogMessage($"{nameof(VirtualEngine)}.{nameof(GetThumbnailAsync)}() - {thumbnailResult}", UserFileSystemPath, default, operationContext);

    return thumbnail;
}

private static async Task<byte[]> StreamToByteArrayAsync(Stream stream)
{
    using (MemoryStream memoryStream = new())
    {
        await stream.CopyToAsync(memoryStream);
        return memoryStream.ToArray();
    }
}
See Also