views:

117

answers:

3

Hey there!

I have seen an application recently what had two simple controls (a treeView and a detailed ListView) what were used for listing directories and files. I know how to do this, but it had another nice feature other than listing files: it loaded info from the system shell, like icons of folders, file specifications (file types mostly, inherited from the system, so if I had an application what modified the SVG file type to "Unknown vectorgraphic stuff" then it showed all SVG file's type as this string before).

I would like to ask You, that how could I make these features easily without using any third party library?

A: 

This may be of help: http://www.codeproject.com/KB/dotnet/System_File_Association.aspx

Partha Choudhury
That tutorial is for associating files to given application. I don't want to do this, but to get system icons used by the different file types and add them to the treeview's nodes. Like the built-in Windows Explorer.
fonix232
+1  A: 

you can get icon for a file by System.Drawing.Icon.ExtractAssociatedIcon()...

Axarydax
Yes I know it but it's kinda frustrating to add any icon with this. Isn't there some kind of automated version of this? I mean extracting the icon and also adding the icon to the node with a simple command?
fonix232
well - I guess you could get all icons for current view and put them into an ImageList of the treeview, then assign image IDs to the nodes.But I'd do owner drawing of the treeview nodes, and on drawing each node I'd retrieve the icon of the file/directory and draw it before item text.
Axarydax
Isn't that kinda slow?And also, for the treeView it only needs the folder icons. My bigger problem is the listView, where it should get ALL icons of the files in there, with file type too...
fonix232
+1  A: 
  1. To get the file icon, use System.Drawing.Icon.ExtractAssociatedIcon.
  2. To get the file type, you need to use the Win32 SHGetFileInfo function.
  3. To get date modified, file size, etc, you can use DirectoryInfo and FileInfo classes.

You can also consider using ready-made controls like Shell MegaPack which show files/folders like this with same icons, details, menus, etc

logicnp
Thanks. That Shell Megapack looks like the best solution, will try it!
fonix232