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.
<Extensions> <desktop3:Extension Category="windows.cloudFiles"> <desktop3:CloudFiles> <desktop3:CustomStateHandler Clsid="754F334F-095C-46CD-B033-B2C0523D2829"/> <desktop3:ThumbnailProviderHandler Clsid="A5B0C82F-50AA-445C-A404-66DEB510E84B"/> <desktop3:ExtendedPropertyHandler Clsid="20000000-0000-0000-0000-000000000001"/> <desktop3:BannersHandler Clsid="20000000-0000-0000-0000-000000000001"/> <desktop3:CloudFilesContextMenus> <desktop3:Verb Id="LockCommand" Clsid="A22EBD03-343E-433C-98DF-372C6B3A1538" /> <desktop3:Verb Id="CommandCompare" Clsid="A54BD1AD-4816-44B0-9247-8F43D8CA7AE7" /> <desktop3:Verb Id="CommandUnmount" Clsid="FF039488-137F-454D-A546-AA329A1D963F" /> </desktop3:CloudFilesContextMenus> </desktop3:CloudFiles> </desktop3:Extension> <com:Extension Category="windows.comServer"> <com:ComServer> <!-- When changing ProgId make sure to change it also in the ThumbnailProvider.cs --> <com:ExeServer DisplayName="WebDAVDrive.ShellExtension" Executable="dummy.exe"> <com:Class Id="A5B0C82F-50AA-445C-A404-66DEB510E84B" /> </com:ExeServer> <com:ExeServer DisplayName="WebDAVDrive.ShellExtension" Executable="dummy.exe"> <com:Class Id="A22EBD03-343E-433C-98DF-372C6B3A1538" /> </com:ExeServer> <com:ExeServer DisplayName="WebDAVDrive.ShellExtension" Executable="dummy.exe"> <com:Class Id="A54BD1AD-4816-44B0-9247-8F43D8CA7AE7" /> </com:ExeServer> <com:ExeServer DisplayName="WebDAVDrive.ShellExtension" Executable="dummy.exe"> <com:Class Id="FF039488-137F-454D-A546-AA329A1D963F" /> </com:ExeServer> <com:ExeServer DisplayName="WebDAVDrive.ShellExtension" Executable="dummy.exe"> <com:Class Id="754F334F-095C-46CD-B033-B2C0523D2829" /> </com:ExeServer> </com:ComServer> </com:Extension> </Extensions>
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 = Program.Settings.RequestThumbnailsFor.Trim().Split("|"); string ext = System.IO.Path.GetExtension(UserFileSystemPath).TrimStart('.'); if (exts.Any(ext.Equals) || exts.Any("*".Equals)) { string ThumbnailGeneratorUrl = Program.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(); } }