Logo
English Russian German French Spanish Italian
contact usprivacy
   Support Forums
chart
• Adjust flexgrid cell
• Animation
• Centering form text
• Coffee machine
• Creating fileshares
• Creating shortcuts
• Custom buttons
• Directory browser
• Disable mouse events
• File search by ext
• File transfer
• File watcher
• Formatting flexgrid
• Get Content Type
• Get HTML source
• Get modem port
• HTTP proxy
• ipconfig
• Large file split/merge
• MAPI
• MCI Sound Player
• Menu with images
• MP3 normalizer
• Net Send
• Netstat 2000
• No duplicate entries
• Outlook Address Book
• Set font color
• Shapes
• SOAP test
• Text-to-image
• Text file viewer
• Text find/replace
• UPS component
• View NT groups
• Word template
• Writing DNS control
    • Using DNS control
• Writing SMTP control
    • Sending email
    • Mailing list
• Writing WhoIs control
    • Using WhoIs control
• View HTML source
OISV - Organization of Independent Software Vendors - Contributing Member
VB projects - Get Content Type

Description: search Registry for content type for the selected file
Minimum requirements: VB6
Download: source code
Screenshot:
VB projects - Get Content Type
Project: EXE
Controls: TextBox txtContentType, CommandButton cmdBrowse (Caption = "Browse"), TextBox txtFile, CommonDialog dlg
Additional references: none
Code:
Option Explicit

Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const KEY_QUERY_VALUE = &H1
Private Const REG_SZ = 1
Private Const ERROR_SUCCESS = 0&
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _
  (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, _
  ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" _
  (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, _
  lpType As Long, lpData As Any, lpcbData As Long) As Long

Private Sub cmdBrowse_Click() dlg.ShowOpen txtFile = dlg.FileName If InStr(txtFile, ".") > 0 Then txtContentType = GetContentType(Mid(txtFile, InStrRev(txtFile, "."))) Else txtContentType = "application/octet-stream" End If End Sub
Private Function GetContentType(ByVal s As String) As String Dim hKey As Long Dim lpSubKey As String Dim lpValueName As String Dim lpType As Long Dim lpData As String Dim lpcbData As Long GetContentType = "application/octet-stream" lpSubKey = "Content Type" If RegOpenKeyEx(HKEY_CLASSES_ROOT, s, 0, KEY_QUERY_VALUE, hKey) = ERROR_SUCCESS Then RegQueryValueEx hKey, lpSubKey, 0, lpType, Chr(0), lpcbData If lpType = REG_SZ Then lpData = Space(lpcbData) If RegQueryValueEx(hKey, lpSubKey, 0, lpType, ByVal lpData, lpcbData) = ERROR_SUCCESS Then GetContentType = Left(lpData, lpcbData) End If End If RegCloseKey hKey End If End Function

Copyright © 1996-2010 OstroSoft. All rights reserved. info@ostrosoft.com