views:

59

answers:

2

Ok this is something new to me....

I have a gridview control which is displaying the files and directory names in one column.

Now i want to display the file icon of that particular file in the other column...

eg test.txt will have a different icon form image1.jpg and here.xsl

i have found two examples but don't kno if they will work or not....

http://www.codeproject.com/KB/custom-controls/AssociatedIconsImage.aspx

or

http://forums.asp.net/t/90921.aspx

how to incorporate this with my gridview..?

thanks

+1  A: 

I found a source that should be useful for you (and with a simple google query btw.): Getting Associated Icons Using C# .

As far as I know, there's no other way than using the shell32 library via interop, as used in the given example.

Webleeuw
yes i did my research also.. and i read shell32 concept also...i found two examples... can u have a look if these are any better... http://forums.asp.net/t/90921.aspx andhttp://www.codeproject.com/KB/custom-controls/AssociatedIconsImage.aspx
The example on CodeProject looks the most clear to me, however, caching icons as files might be a bad idea (what happens when your file associations change?). Caching an icon during the execution of your program might be fine though.As I can see, both examples still use the interop/shell32 way, and albeit with some different code to render the icons, it is still with the same basics.
Webleeuw
+1  A: 

I'm not sure if there is a managed way to this... there very well could be, but the unmanaged way to get this would be to use PInvoke to call SHGetFileInfo. There is sample code on PInvoke.Net which should get you most of the way there.

Nick