How get shell icon of a file in UWP?

杨岑 166 Reputation points
2024-04-28T16:40:31.0933333+00:00

In WIN32 SDK, I can call SHGetFileInfo to get the shell icon of a file used by system (used in File Explorer).

Is there any equivelant API for this purpose in UWP?

Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Junjie Zhu - MSFT 15,366 Reputation points Microsoft Vendor
    2024-04-29T03:08:09.3966667+00:00

    Hi @杨岑

    Welcome to Microsoft Q&A!

    There is StorageFile.GetThumbnailAsync in UWP that can get an adjusted thumbnail image for the file. It is recommended to refer to the File thumbnails sample.

    var picker = new Windows.Storage.Pickers.FileOpenPicker();
    picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
    picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
    picker.FileTypeFilter.Add(".exe");
    //picker.FileTypeFilter.Add(".jpeg");
    //picker.FileTypeFilter.Add(".png");
    Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();
    // Get the thumbnail
    StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem);
    //Set Image source
    BitmapImage bitmapImage = new BitmapImage();
    bitmapImage.SetSource(thumbnail);
    imageTest.Source = bitmapImage;
                
    

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments