Display a files icon

  • Thread starter Anders K. Olsen
  • Start date
A

Anders K. Olsen

Hello group

I'm developing a file application, but I have run into a problem that I hope
you can help with.

My application lists a number of files (names). Now I would like to display
the proper file icon before I display the file name. E.g. if it is a .doc
file, I would like to display the Microsoft Word icon.

The icon should depend on which program is associated with the file type.
Preferably the program that the web client computer has associated with the
file type. I only need something that works under Internet Explorer on
Windows.

Do you have any suggestions?

Regards
Anders
 
E

Eliyahu Goldin

Anders,

You need somehow to get access to Windows API. I heard of WSH API Toolkits
that make possible using Windows API from WSH objects. Try googling it.

Eliyahu
 
S

S.M. Altaf [MVP]

That's an interesting reply, Eli... I hadn't thought of that myself, and if
it works that'd be great. But as far as I've seen and know, it's always up
to you, the developer to associate the icons with the file extensions. You
can use an existing set of GIF images (which you can get from google images
:)) and associate them. I've never seen anyone implement a complex
procedure just for this. Also, keep in mind that new Active Content blockers
in IE could prevent it from working. And it'd probably not work in FireFox
at all.

HTH
 
E

Eliyahu Goldin

If I understood the OP correctly, the whole point is to show the icons that
are associated with the extensions on the client machine. That might be
possible only with Windows API. Note, that I am no more than guessing, I
never did anything like this myself. And the OP cares only about IE in
Windows.

Anyway, it does look that the solution is too complex for the task.

Eliyahu
 
K

Karl Seguin

I agree with Altaf. The way I've done this in the past is get a bunch of
images from various sources (google, screen capture) name them something
like doc.gif jpg.gif pdf.gif and then simply display <extension>.gif

<img src="<%#
System.IO.Path.GetExtension(DataBinder.Eval(Container.DataItem,
"Filename"))%>.gif " />

I actually had an unknown.gif, did a File.Exists("xxx.gif") cached the
resutls and voila..

karl
 
A

Anders K. Olsen

Karl Seguin said:
I agree with Altaf. The way I've done this in the past is get a bunch of
images from various sources (google, screen capture) name them something
like doc.gif jpg.gif pdf.gif and then simply display <extension>.gif

<img src="<%#
System.IO.Path.GetExtension(DataBinder.Eval(Container.DataItem,
"Filename"))%>.gif " />

I actually had an unknown.gif, did a File.Exists("xxx.gif") cached the
resutls and voila..

I was hoping that I could avoid doing that. Considering that Windows already
knows the proper icon, I was hoping that I could persuade Windows to give me
the information.

I found this page on the internet:

http://www.codeproject.com/aspnet/AssociatedIconsImage.asp

I haven't tested it yet, but I intend to take a look at it soon. As far as I
can see, it uses the SHGetFileInfo Shell32 API call. This will hopefully
make it possible to get the icon for the file type as seen from the server.

I will let you know if I can get it to work.

If anybody else know of a better solution, please let me know.

Regards
Anders
 

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

Members online

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,297
Latest member
EngineerD

Latest Threads

Top