![]() |
|
[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 SubUsage: Code: MsgBox(GetFileType("C:\file.txt"))Output: Code: Text DocumentI hope somebody finds it useful. Have a nice day.
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
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. 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 FunctionRE: [VB.Net] Get real filetype name from a file extension - Coder-san - 07-01-2011 Nice and long time no see, Kevin.
|