CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 1999
    Posts
    7

    File association

    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.



  2. #2

    Re: File association

    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.


  3. #3
    Join Date
    Nov 1999
    Posts
    18

    Re: File association

    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


  4. #4
    Join Date
    Nov 1999
    Posts
    7

    Re: File association

    Thanx for you help


  5. #5
    Join Date
    Nov 1999
    Posts
    7

    Re: File association

    Thanx for your help


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

Featured