467,119 Members | 757 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,119 developers. It's quick & easy.

thumbnail of file (like explorer does)

Is there anyway to get a thumbnail of a file similar to the way explorer
does that can be used in an application? I want to for example if i drag a
file over a picture box, if it has the ability to have a thumbnail, show it
in the picture box.

thanks!
Nov 21 '05 #1
  • viewed: 14765
Share:
7 Replies
Hi,

You will have to P/Invoke , look into the archives of
microsoft.public.dotnet.languages.csharp this was answer last week along
with a link to MSDN
take a look at www.pinvoke.net you will find there the signatures you need.

pd:
It's not a good thing to crosspost though.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Brian Henry" <no****@nospam.com> wrote in message
news:uF**************@TK2MSFTNGP15.phx.gbl...
Is there anyway to get a thumbnail of a file similar to the way explorer
does that can be used in an application? I want to for example if i drag a
file over a picture box, if it has the ability to have a thumbnail, show
it in the picture box.

thanks!

Nov 21 '05 #2

Brian Henry wrote:
Is there anyway to get a thumbnail of a file similar to the way explorer
does that can be used in an application? I want to for example if i drag a
file over a picture box, if it has the ability to have a thumbnail, show it
in the picture box.

thanks!


Some code I ran into on the web while looking for something just like
this:

// Please do not remove :)
// Written by Kourosh Derakshan
//
using System.IO;
using System.Drawing.Imaging;

private const int THUMBNAIL_DATA = 0x501B;
/// <summary>
/// Gets the thumbnail from the image metadata. Returns null of no
thumbnail
/// is stored in the image metadata
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
Image GetThumbnail (string path)
{
FileStream fs = File.OpenRead (path);
// Last parameter tells GDI+ not the load the actual image data
Image img = Image.FromStream (fs, false, false);
// GDI+ throws an error if we try to read a property when the image
// doesn't have that property. Check to make sure the thumbnail
property
// item exists.
bool propertyFound = false;
for (int i=0; i<img.PropertyIdList.Length; i++)
if (img.PropertyIdList[i] == THUMBNAIL_DATA)
{
propertyFound = true;
break;
}

if (!propertyFound)
return null;

PropertyItem p = img.GetPropertyItem (THUMBNAIL_DATA);
fs.Close();
img.Dispose();
// The image data is in the form of a byte array. Write all
// the bytes to a stream and create a new image from that stream
byte[] imageBytes = p.Value;
MemoryStream stream = new MemoryStream (imageBytes.Length);
stream.Write (imageBytes, 0, imageBytes.Length);

return Image.FromStream(stream);
}

A big thanks to Kourosh.

Matt

Nov 21 '05 #3
You need to use the shells IExtractImage interface.
This will show you how...
http://www.vbaccelerator.com/home/NE...on/article.asp
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Brian Henry" <no****@nospam.com> wrote in message
news:uF**************@TK2MSFTNGP15.phx.gbl...
Is there anyway to get a thumbnail of a file similar to the way explorer
does that can be used in an application? I want to for example if i drag a
file over a picture box, if it has the ability to have a thumbnail, show
it in the picture box.

thanks!

Nov 21 '05 #4
well that works the best so far, I can get it to give me a thumb of a DOC
and Visio file which I need, but I also need PDF thumbs (Acrobat 7 does
thumbs now) and when i select a pdf with that test app it says "Failed to
get thumbnail: The data necessary to complete this operation is not yet
available."
Nov 21 '05 #5
Are the thumbnails visible in the explorer window? If they are they should
be extractable by this method. If the thumbnails are just specific to the
file open dialog in acrobat I would suspect a custom implementation rather
than a shell integration solution.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Brian Henry" <no****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
well that works the best so far, I can get it to give me a thumb of a DOC
and Visio file which I need, but I also need PDF thumbs (Acrobat 7 does
thumbs now) and when i select a pdf with that test app it says "Failed to
get thumbnail: The data necessary to complete this operation is not yet
available."

Nov 21 '05 #6
yes, they are visible in explorer under acrobat reader 7
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Are the thumbnails visible in the explorer window? If they are they should
be extractable by this method. If the thumbnails are just specific to the
file open dialog in acrobat I would suspect a custom implementation rather
than a shell integration solution.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Brian Henry" <no****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
well that works the best so far, I can get it to give me a thumb of a DOC
and Visio file which I need, but I also need PDF thumbs (Acrobat 7 does
thumbs now) and when i select a pdf with that test app it says "Failed to
get thumbnail: The data necessary to complete this operation is not yet
available."


Nov 21 '05 #7
Use the IExtractImage interface via P/Interop.

-Atul, Sky Software http://www.ssware.com
Shell MegaPack ActiveX & .Net
Drop In Windows Explorer like Shell Browsing GUI controls for your app.

"Brian Henry" <no****@nospam.com> wrote in message
news:uF**************@TK2MSFTNGP15.phx.gbl...
Is there anyway to get a thumbnail of a file similar to the way explorer
does that can be used in an application? I want to for example if i drag a
file over a picture box, if it has the ability to have a thumbnail, show
it in the picture box.

thanks!

Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ole | last post: by
5 posts views Thread by Brian Henry | last post: by
4 posts views Thread by moondaddy | last post: by
1 post views Thread by Xah Lee | last post: by
10 posts views Thread by Mike Copeland | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.