-
Aug 15th, 2014, 12:52 PM
#1
(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
-
Aug 15th, 2014, 01:07 PM
#2
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.
-
Aug 15th, 2014, 01:12 PM
#3
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".
-
Aug 15th, 2014, 01:29 PM
#4
Re: Is a file type extension registered?
Originally Posted by jmcilhinney
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|