Search code examples
c#.netwindows-api-code-pack

Get thumbnail of Network DWG file by Windows API Code Pack


I use the below code to get the DWG file thumbnail using the Windows API Code Pack:

ShellFile shellFile = ShellFile.FromFilePath(mediaInfo.Filename);
return shellFile.Thumbnail.LargeBitmap;

But this works for local DWG files only, and returns the blank document thumbnails for network based files.

However I see the thumbnails of network files via the Windows Explorer (I am on Win 8.1).

Any advice would be appreciated.


Solution

  • There must be something wrong happening on your side because the following code works here:

    using System;
    using System.Drawing;
    using System.IO;
    using System.Windows.Forms;
    using Microsoft.WindowsAPICodePack.Shell;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                string fileName = @"\\PC\Users\Public\bitmap.bmp";
                ShellFile shellFile = ShellFile.FromFilePath(fileName);
                ShellThumbnail thumbnail = shellFile.Thumbnail;
                var pictureBox = new PictureBox
                {
                    Image = thumbnail.Bitmap,
                    Dock = DockStyle.Fill
                };
                Controls.Add(pictureBox);
            }
        }
    }
    

    enter image description here

    Check the following:

    • try with another extension to see if it affects all of them or not
    • try to re-register thumbnails handlers, just a guess but SageThumbs might fix this by registering it and unregistering it as the default handler for extensions
    • if that matters, I've used the Code Pack I've myself pushed to NuGet : https://www.nuget.org/packages/WindowsAPICodePack-Shell/ (not sure that might be the issue since I haven't changed anything)