解决方法
您将需要使用
Windows API
SHGetFileInfo function
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Auto)] public struct SHFILEINFO { public IntPtr hIcon; public int iIcon; public uint dwAttributes; [MarshalAs(UnmanagedType.ByValTStr,SizeConst = 260)] public string szDisplayName; [MarshalAs(UnmanagedType.ByValTStr,SizeConst = 80)] public string szTypeName; };
请注意,这只是存储在Windows注册表中的当前“友好名称”,它只是一个标签(但对于您的情况可能足够好).
szTypeName和szDisplayName之间的区别描述在MSDN:
szTypeName: Null-terminated string that
describes the type of file.szDisplayName: Null-terminated string
that contains the name of the file as
it appears in the Windows shell,or
the path and name of the file that
contains the icon representing the
file.
为了更准确地确定文件类型,您需要阅读每个文件的第一个字节块,并将其与已发布的文件规范进行比较.有关文件格式的信息,请参阅Wotsit网站.