Click to See Complete Forum and Search --> : File association


Warrier
November 24th, 1999, 01:18 PM
How to get file assocaition in VB ?I have a file open dialog box.If I select a doc file it should open it with latest MSword,if it is pdf it should open in Acrobat reader etc.I can't use word objects or shell command bcoz i will have to hard code the progID which is diff. for diff. versions of word. like Word.Application.8, Word.Document.6 etc.
Any suggestions ???
Thanx in advance.

czimmerman
November 24th, 1999, 01:52 PM
See http://www.freevbcode.com/ShowCode.Asp?ID=12. Though the example is title Open a web page in the default browser, it will actually open any file in the program with which it is associated.

psiclone
November 24th, 1999, 02:04 PM
You can however, use the ShellExecute API method. This runs the default program that the file is associated with.

Paste the following declaration into your VB project:


private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(byval hwnd as Long, byval lpOperation as string, byval lpFile as string, _
byval lpParameters as string, byval lpDirectory as string, byval nShowCmd _
as Long) as Long




Then, to run the file use the following code:


ShellExecute(me.hWnd, "Open", FileName, "", "", 1)



replacing FileName with the name and path of the file.

psiclone

Warrier
November 24th, 1999, 03:07 PM
Thanx for you help

Warrier
November 24th, 1999, 03:08 PM
Thanx for your help