有没有办法让VB.net中的Windows资源管理器中显示的文件类型
例如,在 Windows 资源管理器的详细信息视图中可以看到
Name Date Modified Type Size
A.PDF 05/06/2017 5:54PM Adobe Acrobat reader 150kb
B.DOCX 05/06/2017 5:00PM Microsoft Word Document 100kb
etc.
我想得到类型。我似乎无法找到到达那里的方法。感觉这应该是很容易的事。
Dim infoReader As System.IO.FileInfo
infoReader = My.Computer.FileSystem.GetFileInfo(txtFileName.Text)
FileInfo 获取修改后的数据和文件大小......但不是类型。
感谢论坛帮助!
。 IE。对于 .pdf 文件,显示为“adobe acrobat 文档”。 .xls 文件将显示“Microsoft Excel 工作表”
您可以使用下面的 VB.net 代码来获取文件类型描述。基本上你必须使用SH获取文件信息API 来获取该信息。
Imports System.Runtime.InteropServices
Module Get_File_Type
Sub Main()
Dim info As New NativeMethods.SHFILEINFO()
Dim fileName As String = "C:\TEST\TEST.xlsx"
Dim dwFileAttributes As UInteger = NativeMethods.FILE_ATTRIBUTE.FILE_ATTRIBUTE_NORMAL
Dim uFlags As UInteger = CUInt(NativeMethods.SHGFI.SHGFI_TYPENAME Or NativeMethods.SHGFI.SHGFI_USEFILEATTRIBUTES)
NativeMethods.SHGetFileInfo(fileName, dwFileAttributes, info, CUInt(Marshal.SizeOf(info)), uFlags)
Console.WriteLine(info.szTypeName)
Console.ReadLine()
End Sub
End Module
NotInheritable Class NativeMethods
Private Sub New()
End Sub
<StructLayout(LayoutKind.Sequential)> _
Public Structure SHFILEINFO
Public hIcon As IntPtr
Public iIcon As Integer
Public dwAttributes As UInteger
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
Public szDisplayName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _
Public szTypeName As String
End Structure
Public NotInheritable Class FILE_ATTRIBUTE
Private Sub New()
End Sub
Public Const FILE_ATTRIBUTE_NORMAL As UInteger = &H80
End Class
Public NotInheritable Class SHGFI
Private Sub New()
End Sub
Public Const SHGFI_TYPENAME As UInteger = &H400
Public Const SHGFI_USEFILEATTRIBUTES As UInteger = &H10
End Class
<DllImport("shell32.dll")> _
Public Shared Function SHGetFileInfo(pszPath As String, dwFileAttributes As UInteger, ByRef psfi As SHFILEINFO, cbSizeFileInfo As UInteger, uFlags As UInteger) As IntPtr
End Function
End Class
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)