Sinisterly
[VB.Net] Get real filetype name from a file extension - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Visual Basic & .NET Framework (https://sinister.li/Forum-Visual-Basic-NET-Framework)
+--- Thread: [VB.Net] Get real filetype name from a file extension (/Thread-VB-Net-Get-real-filetype-name-from-a-file-extension)



[VB.Net] Get real filetype name from a file extension - Coder-san - 06-22-2011

Made this for a custom explorer I'm making.

Code:
Private Function GetFileType(ByVal FileName As String) As String GetFileType = "" Dim extensionName As String = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\" & FileName.Substring(FileName.LastIndexOf(".")), "", FileName.Substring(FileName.LastIndexOf("."))) GetFileType = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\" & extensionName, "", FileName.Substring(FileName.LastIndexOf("."))) End Sub

Usage:
Code:
MsgBox(GetFileType("C:\file.txt"))

Output:
Code:
Text Document

I hope somebody finds it useful. Have a nice day. Smile


RE: [VB.Net] Get real filetype name from a file extension - 1234hotmaster - 06-22-2011

helpful for a file searcher i never even thought such thing was possible Biggrin


RE: [VB.Net] Get real filetype name from a file extension - kevininstructor - 07-01-2011

(06-22-2011, 11:08 AM)Coder-san Wrote: Made this for a custom explorer I'm making.

Code:
Private Function GetFileType(ByVal FileName As String) As String GetFileType = "" Dim extensionName As String = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\" & FileName.Substring(FileName.LastIndexOf(".")), "", FileName.Substring(FileName.LastIndexOf("."))) GetFileType = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\" & extensionName, "", FileName.Substring(FileName.LastIndexOf("."))) End Sub

Usage:
Code:
MsgBox(GetFileType("C:\file.txt"))

Output:
Code:
Text Document

I hope somebody finds it useful. Have a nice day. Smile

Nice! I made some changes so it will work with Option Strict On and shorten the code up a tag bit.
Code:
Public Function GetFileType(ByVal FileName As String) As String Dim Ext As String = IO.Path.GetExtension(FileName) Return My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\" & My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\" & Ext, "", Ext).ToString, "", Ext).ToString End Function



RE: [VB.Net] Get real filetype name from a file extension - Coder-san - 07-01-2011

Nice and long time no see, Kevin. Smile