IFileSystemItemGetThumbnailAsync Method |
Namespace: ITHit.FileSystem
Exception | Condition |
---|---|
NotImplementedException | If no thumbnail should be displayed. |
To show thumbnails in your virtual drive on Windows platform follow these steps:
Thumbnails functionality does NOT require package or application identity.
The code below is part of 'WebDAVDrive' C# sample provided with the SDK.
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(); } }