我如何在C#中常见的文件类型图标?文件类型、图标、常见、如何在

2023-09-02 21:25:13 作者:心软脾气硬

作为这对越来越图标,使问题中常见的文件类型,它很可能为Windows程序,以获得图标使用C ++ API壳牌注册的文件类型。这些图标可能会或磁盘上可能不存在 - 例如,我们想使自己的自定义文件浏览器,并要显示与文件系统相关的图标

As seen in This SO question on getting icons for common file types, it's quite possible for a windows program to get the icons for a registered file type using the C++ Shell API. These icons may or may not exist on disk - for example, we wanted to make our own custom file browser and want to display the system-associated icon with the file.

是否有原生的C#的方式来获得的图标为各种文件类型(如果有的话,怎么样),还是必须通过的PInvoke与外壳API做了什么?

Is there a native C# way to get the icons for various file types (and if so, how) or must it be done through PInvoke with shell API?

和作为后续行动,如果有做它的原生.NET的方式,有没有做它的跨平台的方式?

And as a follow up, if there is a native .NET way of doing it, is there a cross-platform way of doing it?

推荐答案

看看:http://mvolo.com/blogs/serverside/archive/2007/01/11/Display-$p$ptty-file-icons-in-your-ASP.NET-applications-with-IconHandler.aspx

这不是最干净的解决方案,但它的工作原理。否则,试图让你的手的图标即是基于MIME类型或文件扩展名的库。

It's not the cleanest solution but it works. Otherwise, try to get your hands on a library of Icons that's based on mime type or file extension.