• 0

[VB.NET] Get File type by extension


Question

Hello gang,

Writing a little app to help users to create projects of files related to other files (rather simple, I know) and while I can get the associated icon via the "ExtractAssociatedIcon" function I cannot find a way to get the File's document type by it's association. For example if you look at the status bar of the Windows Explorer you can see "Adobe Photoshop Image" when I select a PSD file.

Any ideas?

post-45653-0-70870700-1305577789.jpg

Link to comment
https://www.neowin.net/forum/topic/997870-vbnet-get-file-type-by-extension/
Share on other sites

7 answers to this question

Recommended Posts

  • 0
  On 17/05/2011 at 11:30, mute~ said:

Is this of any help?

Private Function lol(ByVal extension As String) As String
        Dim readValue As String
        readValue = My.Computer.Registry.GetValue _
        ("HKEY_CLASSES_ROOT\" & extension, "", "ExtensionNotFound")
        Return readValue
End Function

Thanks, that kind of works, I was hoping for a native function as this returns a badly formatted string. eg: ".doc" returns "Word.Document.8"

But thanks, it is something. Have a great day.

  • 0
  On 17/05/2011 at 12:32, jameswjrose said:

Thanks, that kind of works, I was hoping for a native function as this returns a badly formatted string. eg: ".doc" returns "Word.Document.8"

But thanks, it is something. Have a great day.

Yeah sorry, best I could think of while trying to navigate ;)

Will have a think about it when I get back on Monday if no-one has solved it before then.

  • 0
  On 18/05/2011 at 11:34, mute~ said:

Yeah sorry, best I could think of while trying to navigate ;)

Will have a think about it when I get back on Monday if no-one has solved it before then.

Please, do not apologize. Thank you very much for an answer! Have a great week.

  • 0
  On 17/05/2011 at 12:32, jameswjrose said:

Thanks, that kind of works, I was hoping for a native function as this returns a badly formatted string. eg: ".doc" returns "Word.Document.8"

But thanks, it is something. Have a great day.

Then use that string to get it, eg HKEY_CLASSES_ROOT\Word.Document.8 and it has "Microsoft Office Word 97 - 2003 Document" as the default value.

  • Like 1
  • 0

Hi,

Managed to find some free time, hope this is more helpful:

    Public Shared Function GetFileExtType(ByVal fileExtension As String) As String
        Dim FileExtensionName As String = ""

        For Each subKey As String In Registry.ClassesRoot.GetSubKeyNames()
            If String.IsNullOrEmpty(subKey) Then
                Continue For
            End If

            If subKey.CompareTo(fileExtension) = 0 Then
                Dim defaultValue As String = Registry.ClassesRoot.OpenSubKey(subKey).GetValue("").ToString()

                If defaultValue.Length = 0 Then
                    Exit For
                End If

                If FileExtensionName.Length = 0 Then
                    FileExtensionName = defaultValue
                    fileExtension = FileExtensionName
                Else
                    If defaultValue.Length > 0 Then
                        FileExtensionName = defaultValue
                    End If
                    Exit For
                End If
            End If
        Next
        Return FileExtensionName
    End Function

  • 0
  On 19/05/2011 at 19:01, mute~ said:

Hi,

Managed to find some free time, hope this is more helpful:

    Public Shared Function GetFileExtType(ByVal fileExtension As String) As String
        Dim FileExtensionName As String = ""

        For Each subKey As String In Registry.ClassesRoot.GetSubKeyNames()
            If String.IsNullOrEmpty(subKey) Then
                Continue For
            End If

            If subKey.CompareTo(fileExtension) = 0 Then
                Dim defaultValue As String = Registry.ClassesRoot.OpenSubKey(subKey).GetValue("").ToString()

                If defaultValue.Length = 0 Then
                    Exit For
                End If

                If FileExtensionName.Length = 0 Then
                    FileExtensionName = defaultValue
                    fileExtension = FileExtensionName
                Else
                    If defaultValue.Length > 0 Then
                        FileExtensionName = defaultValue
                    End If
                    Exit For
                End If
            End If
        Next
        Return FileExtensionName
    End Function

Thanks, you're too kind. It works perfectly.

If you care, here is the app it is going into: Blissgig.com: b.Link

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Lol tf you are talking about. People are PAYING by using this app exclusively, just indirectly. Do you have any idea how much facebook charges for api access to WhatsApp which has become more or less a monopoly in e-commerce.
    • My kid tried, so I took her to Microcenter and showed her the differences in price as well as storage and specs. We bought a Windows machine. She loves it, and is off to college this fall with her gaming level windows laptop at the price of a Mac that came with a 512GB SSD, and half the RAM.
    • Hasleo Backup Suite Free 5.4.2.1 by Razvan Serea Hasleo Backup Suite Free is a free Windows backup and restore software, which embeds backup, restore and cloning features, it is designed for Windows operating system users and can be used on both Windows PCs and Servers. The backup and restore feature of Hasleo Backup Suite can help you back up and restore the Windows operating systems, disks, partitions and files (folders) to protect the security of your Windows operating system and personal data. The cloning feature of Hasleo Backup Suite can help you migrate Windows to another disk, or easily upgrade a disk to an SSD or a larger capacity disk. System Backup & Restore / Disk/Partition Backup & Restore Backup Windows operating system and boot-related partitions, including user settings, drivers and applications installed in these partitions, which ensures that you can quickly restore your Windows operating system once it crashes. Viruses, power failure, or other unknown reasons may cause data loss, so it is a good habit to regularly back up the drive that stores important files, you can at least recover lost files from the backup image files in the event of a disaster. System Clone / Disk Clone / Partition Clone Migrate the Windows operating system from one disk to another SSD or larger disk without reinstalling Windows, applications and drivers. Clone entire disk to another disk and ensure that the contents of the source disk and the destination disk are exactly the same. Clone a partition completely to the specified location on the current disk or another disk and ensure that the data will not be changed. File Backup & Restore Back up specified files(folders) instead of the entire drive to another location to protect your data, so you can quickly restore files(folders) from the backup image files when needed. Incremental/Differential/Full Backup Different backup modes are supported, you can flexibly choose data protection schemes, which can improve backup performance and save storage space while ensuring data security. Delta Restore Delta restore uses advanced delta detection technology to check the changed blocks on the destination drive and restore only the changed blocks, so it has a faster restore speed than the traditional full restore. Universal Restore This feature can help us restore the Windows operating system to computers with different hardware and ensure that Windows can work normally without any hardware compatibility issues. Hasleo Backup Suite 5.4.2.1 changelog: The program crashes when sending emails Application notifications cannot be displayed in the Windows Notification Center Updated Italian and German translations Fixed other minor bugs Download: Hasleo Backup Suite 5.4.2.1 | 33.9 MB (Freeware) Links: Hasleo Backup Suite Website | Hasleo Backup Suite Guide | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • 99% of Control Panel will be moved to Settings. Then by 2050, 20% of settings will have been moved to the Configuration Menu. I have no issues with Settings as it exists now in Windows 11. Bring everything over and be done with it.
    • We collect the few carcasses we get (as long as drivers report them, as they should) and while we have our fair share, we don't have nearly enough crashes with deer "to paint the roads with deer carcasses" in Finland. Also, if you can't handle the risks, DO NOT DRIVE. I really don't want everything to be so simple and stupid, that I don't have to worry about my surroundings (I also hate Apple devices because they kind of decide everything for you and offer very little customization vs. Android). Most people probably encounter much higher risks and dangers in their daily jobs than they encounter on roads. Just a few weeks ago I twisted my anckle at work while walking and I haven't had even a near miss with an animal in traffic for many years despite driving something like 27000+ km/year (there were a couple of off years in there too) and seeing many deer, a few moose and many smaller creatures on the road. I find it extremely rare to have deer stumble directly in front of me - it happens, but in my opinion not nearly enough to warrant considering it super dangerous (I actually find it exhilarating when it does happen as it changes the daily commute and it actually requires me to stay focused). It is probably more common to have some idiot with their face glued to their phone wonder in front of you or a kid on an electric scooter disregard all traffic rules. Here in the Nordics we also have plenty of snow and that kind of f's up anything that relies on lines or other clear lane indicators. The one time I have (kind of) started raging while driving was when I had a loan car from service and it had lane guidance. That freaking thing basically felt like it wanted to hit every pothole and bump it could and I really, really freaking hated it (came close to ripping the whole steering wheel of, I tell you . Didn't feel safer at all, quite the contrary, and it distracted me from the road more than anything else I've driven before, constantly fighting that f'ing thing to go where I wanted it to go (no clear lines, a crack in the pavement, etc. and it became confused as hell and required more adjusting than any traditional car). Also noteworthy that globally the amount of people with driver's licenses is pretty low (like under 20 %), many countries have great public transport systems and many walk and cycle (even during the winter).
  • Recent Achievements

    • Contributor
      GravityDead went up a rank
      Contributor
    • Week One Done
      BlakeBringer earned a badge
      Week One Done
    • Week One Done
      Helen Shafer earned a badge
      Week One Done
    • First Post
      emptyother earned a badge
      First Post
    • Week One Done
      Crunchy6 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      660
    2. 2
      ATLien_0
      266
    3. 3
      Michael Scrip
      235
    4. 4
      Steven P.
      164
    5. 5
      +FloatingFatMan
      150
  • Tell a friend

    Love Neowin? Tell a friend!