Reading File Types in VB.NET

  • Thread starter Thread starter Ragav
  • Start date Start date
R

Ragav

Hi,

I would like to read the type of files (similar to the 'Type' column
in Windows explorer. Where can I get that Information? Is there any
place in the registry where I can read it from?

Thanks a lot.
Ragav
 
(e-mail address removed) (Ragav) scripsit:
I would like to read the type of files (similar to the 'Type' column
in Windows explorer. Where can I get that Information? Is there any
place in the registry where I can read it from?

Do you want to get the type's description?

\\\
Imports System.Runtime.InteropServices

Public Class Form1
Inherits System.Windows.Forms.Form

Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" ( _
ByVal pszPath As String, _
ByVal dwFileAttributes As Int32, _
ByRef psfi As SHFILEINFO, _
ByVal cbFileInfo As Int32, _
ByVal uFlags As Int32 _
) As IntPtr

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Private Structure SHFILEINFO
Public hIcon As Int32
Public iIcon As Int32
Public dwAttributes As Int32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
Public szDisplayName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _
Public szTypeName As String
End Structure

Private Const SHGFI_TYPENAME As Int32 = &H400

Private Sub Test()
Dim x As SHFILEINFO
Call SHGetFileInfo("C:\test_tl\ausarb.tex", 0, x, Len(x), SHGFI_TYPENAME)
MsgBox(x.szTypeName)
End Sub
End Class
///
 
Back
Top