c# - UWP get shell icon for a file -


most solutions here use system.drawing not available in uwp afaik. getthumbnailasync() job non-image files. image files scaled preview, regardless of passed arguments.

file thumbnails, image , text

i'd have shell file icon instead of tiny preview left of file name, here:

shell file icon

any thoughts?

thanks

ps: have found hack: create 0 byte temp file same extension , make thumbnail of it. hope though there better solution...

well here's helper metod uses dummy file approach (place in static class):

public async static task<storageitemthumbnail> getfileicon(this storagefile file, uint size = 32) {     storageitemthumbnail icontmb;     var imgext = new[] { "bmp", "gif", "jpeg", "jpg", "png" }.firstordefault(ext => file.path.tolower().endswith(ext));     if (imgext != null)     {         var dummy = await applicationdata.current.temporaryfolder.createfileasync("dummy." + imgext, creationcollisionoption.replaceexisting); //may overwrite existing         icontmb = await dummy.getthumbnailasync(thumbnailmode.singleitem, size);     }     else     {         icontmb = await file.getthumbnailasync(thumbnailmode.singleitem, size);     }     return icontmb; } 

usage example:

var icon = await file.getfileicon(); var img = new bitmapimage(); img.setsource(icon); 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -