Results 1 to 4 of 4

Thread: (resolved) Is a file type extension registered?

  1. #1

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,757

    (resolved) Is a file type extension registered?

    Hey all,
    My application creates a csv file and if the computer has an application associated with a csv extension(typically Excel) it should open the file. If however there is no application registered, I want to save the file. According to the internets, file registrations are maintained in the HKEY_CLASSES_ROOT hive in the registry.

    I am just curious if
    1) is there a framework method for getting the file type registrations, and
    2) if not does any know if looking for the extension in the HKCR hive is the best method and if it is good for cross-platform method (i.e Win XP, 7, 8 and 8.1)?
    thanks
    kevin
    Last edited by kebo; Aug 15th, 2014 at 01:29 PM.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Is a file type extension registered?

    This works:
    Code:
    Public Class ExeFromExtension
    
        Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Integer
    
        Public Shared Function Find(ext As String) As String
            Dim ExeFileName As String = New String(" "c, 255)
            Dim RetVal = FindExecutable(ext, vbNullString, ExeFileName)
            ExeFileName = ExeFileName.Trim
            If RetVal <= 32 Or ExeFileName = String.Empty Then
                'NO ASSOCIATION FOUND, OR FILE DID NOT EXIST THAT 
                'WAS PASSED IN TO CHECK AGAINST
                Return String.Empty
            Else
                'RETURN FULL PATH OF ASSOCIATED EXE
                Return ExeFileName
            End If
        End Function
    
    End Class
    usage:
    Code:
            Dim myExeName = ExeFromExtension.Find("C:\work\test.csv")
            MessageBox.Show(myExeName)
    Note the file actually needs to exist you pass in to check against.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,301

    Re: Is a file type extension registered?

    I haven't tested this theory but, from what I've read, I think that you should be able to create a ProcessStartInfo with your file path and then check the Verbs property. If there is a default application associated with that file type then that Verbs array should include "Open".

  4. #4

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,757

    Re: Is a file type extension registered?

    Quote Originally Posted by jmcilhinney View Post
    I haven't tested this theory but, from what I've read, I think that you should be able to create a ProcessStartInfo with your file path and then check the Verbs property. If there is a default application associated with that file type then that Verbs array should include "Open".
    Indeed.
    Thanks JM. That is a good find
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width