Getting Icon of Files

  • Thread starter Brian P. Hammer
  • Start date
B

Brian P. Hammer

All - How can I get an icon associated with a particular file extension and
then get the icon displayed in a picturebox?

I have an app with a picturebox. The picturebox displays pictures and other
files stored in SQL. If the SQL data is an image, it displays the image but
if it is, say a word doc, it displays an image I created that says "Not an
Image". I would like to display the icon associated with the particular
file type inspectead. So, when a user adds a word doc, the icon is shown in
the picturebox or adobe or whatever else the user might save to the
database.

Better even yet, would be to load a preview of the document into the
picturebox, like Adobe does in the "thumbnail" view of a windos folder.

Thanks,
Brian
 
B

Bob Powell [MVP]

This is a shell function using the IExtractImage interface.

Google for this interface such as "IExtractImage +C#"

--
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.
 
B

Brian P. Hammer

Thanks Bob.


Bob Powell said:
This is a shell function using the IExtractImage interface.

Google for this interface such as "IExtractImage +C#"

--
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.
 
B

Brian P. Hammer

Bob - Not exactly what I am looking for I think. I have files stored in a
database. Let's say the user views DB stored file 2 in the picturebox. I
want to look at the extension field and get the icon associated with it, not
a thumbnail. If file 2 is a Word doc, I would expect to see the MSWord icon
appear.

Maybe I missed something in IExtractInage interface?!? The couple sample
projects and google links don't do that. They get a thumbnail of an image
file. I want to get the Icon associated with the type of file. The file
extension value I save in my database as well.

Thanks,
Brian
 
M

Michael Phillips, Jr.

Use SHGetFileInfo with the SHGFI_ICON flag to retrieve a handle to the icon
associated with the file.
 
B

Brian P. Hammer

Thanks... That is what I am looking for.


Michael Phillips said:
Use SHGetFileInfo with the SHGFI_ICON flag to retrieve a handle to the
icon associated with the file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top