2

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.

Murat Korkmaz
  • 1,329
  • 2
  • 19
  • 37
  • Hi, Did you get a fix for this??. I have the same problem. My original code is the same as yours and works fine in all local files and most network files but it does not work for some networks. I'm thinking on copying the network file to a temp directory, and get the thumbnail for that but I guess it is going to be slow. – DGaleano Jul 01 '20 at 18:10

1 Answers1

2

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)
aybe
  • 15,516
  • 9
  • 57
  • 105
  • Aybe, thanks for the contribution. Yep, the above code works for images file. But I am trying to render the DWG files, and the above code works for local DWG files only – Murat Korkmaz Dec 05 '14 at 15:14
  • Ah yes, unfortunately I don't have Autocad to test out ! But one option emerges though, have you tried to change the `thumbnail.RetrievalOption` flag before getting the bitmap ? – aybe Dec 05 '14 at 16:07
  • Unfortunatelly it doesn't help. I get the blank document icon for remote DWG files. – Murat Korkmaz Dec 08 '14 at 15:28
  • You can always try to use the source code instead of the NuGet package, do a comparison between a working extension and a DWG file to find what's the cause. – aybe Dec 08 '14 at 17:25