Login Register






[VB.Net] Get real filetype name from a file extension filter_list
Author
Message
[VB.Net] Get real filetype name from a file extension #1
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
[Image: rytwG00.png]
Redcat Revolution!

[+] 1 user Likes Coder-san's post

RE: [VB.Net] Get real filetype name from a file extension #2
helpful for a file searcher i never even thought such thing was possible Biggrin
Pierce the life fibers with your drill.


RE: [VB.Net] Get real filetype name from a file extension #3
(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
Conflict is inevitable, but combat is optional
My humble self-defense site
Use Option Strict = On when coding with VB.NET


RE: [VB.Net] Get real filetype name from a file extension #4
Nice and long time no see, Kevin. Smile
[Image: rytwG00.png]
Redcat Revolution!