| | |
Get File Type
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Aug 2009
Posts: 2
Reputation:
Solved Threads: 1
You need to read the registry to get that info.
Look in HKEY_CLASSES_ROOT. Each extension registered on that computer will have a key in this section of the registry. For instance there will be a .txt key and a .doc key. Add a textbox and a button to a form and enter ".txt" in the textbox and click the button.
Look in HKEY_CLASSES_ROOT. Each extension registered on that computer will have a key in this section of the registry. For instance there will be a .txt key and a .doc key. Add a textbox and a button to a form and enter ".txt" in the textbox and click the button.
VB.NET Syntax (Toggle Plain Text)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim readValue As String readValue = My.Computer.Registry.GetValue _ ("HKEY_CLASSES_ROOT\" & TextBox1.Text, "", "ExtensionNotFound") MsgBox("The value is " & readValue) End Sub
Read this article - http://www.cryer.co.uk/filetypes/
Failure is not fatal, but failure to change might be. - John Wooden
•
•
Join Date: Aug 2009
Posts: 12
Reputation:
Solved Threads: 4
The following code was tested on Windows 7 RC. It should work on all the older operating systems too, but let me know if you face any problems.
vb.net Syntax (Toggle Plain Text)
Imports Microsoft.Win32 Public Shared Function GetFileType(ByVal fileExtension As String) As String Dim fileType As String = "" 'Search all keys under HKEY_CLASSES_ROOT For Each subKey As String In Registry.ClassesRoot.GetSubKeyNames() If String.IsNullOrEmpty(subKey) Then Continue For End If If subKey.CompareTo(fileExtension) = 0 Then 'File extension found. Get Default Value Dim defaultValue As String = Registry.ClassesRoot.OpenSubKey(subKey).GetValue("").ToString() If defaultValue.Length = 0 Then 'No File Type specified Exit For End If If fileType.Length = 0 Then 'Get Initial File Type and search for the full File Type Description fileType = defaultValue fileExtension = fileType Else 'File Type Description found If defaultValue.Length > 0 Then fileType = defaultValue End If Exit For End If End If Next Return fileType End Function 'Example USAGE Dim fileType = GetFileType(".txt")
Last edited by JadeSimon; Aug 16th, 2009 at 3:04 am. Reason: Added the imports statement
![]() |
Similar Threads
- upload download any file type to sql DB using c# windows form (C#)
- Creating a new file type - and creating Search function (C#)
- File of *Type* (Pascal and Delphi)
- Windows Explorer forces file type search (Windows NT / 2000 / XP)
- File type help (Computer Science)
- Anyone know what .AL file type is. Please help (Mac Software)
- Convert any file type to pdf with distiller (C#)
- How do I get the default action of a specific file type? (Visual Basic 4 / 5 / 6)
- Windows media player- Does not support file type! (Windows Software)
Other Threads in the VB.NET Forum
- Previous Thread: Collection of abstract class
- Next Thread: Help about my statement
| Thread Tools | Search this Thread |
.net .net2008 30minutes 2005 2008 access account arithmetic array basic bing button buttons center check code combobox component connectionstring crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dropdownlist excel fade file-dialog filter folder ftp generatetags google gridview hardcopy images input insert intel internet mobile monitor ms net networking objects output panel passingparameters peertopeervideostreaming picturebox picturebox1 port position print printing problem problemwithinstallation project save searchbox searchvb.net select serial shutdown soap survey table tcp temperature text textbox timer timespan toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year






