简体   繁体   中英

C# Working with Zip Files via .Net

I have a program that can display the contents of a .zip file in a TreeView control. There is one thing I cannot figure out though.

What if we want to display file icons beside our files in the TreeView control? How do you get the file icon for a ZipArchiveEntry. I can't find any info on how to do this and there isn't a method for it on the ZipArchiveEntry class as maybe there should be. Same is true of the .Net File class.

Does anyone know how to get the file icon for a ZipArchiveEntry so I can display it next to the filename in the TreeView control? One would think getting the icon of a file would be a simple thing, but not so much...

You can use this ( http://www.brad-smith.info/blog/archives/164 ) utility.

If you have extension you can use second example.

Only Note that icon of specified file or extension should existed in Windows.

Icon smallIcon = IconTools.GetIconForFile(
    @"C:\Windows\System32\notepad.exe",
    ShellIconSize.SmallIcon
);

Icon largeIcon = IconTools.GetIconForExtension(".html", ShellIconSize.LargeIcon);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM