Results 1 to 14 of 14

Thread: [2005] Open your program by opening a file

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    87

    [2005] Open your program by opening a file

    Well this is my question:

    With my program i created a file. Example: file.myE(xtention)

    Now ill tell windows that all the *.myE must be opend by my own programm: iOpenYou.exe.

    How do i tell in my program wich method i must call when windows is sending that file to my .exe? I know that in Java it is the contructor Main(args[] as string) and you can extract the filename from args[].

    But can i do this in VB.net?

    Greets

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Open your program by opening a file

    You will want to create a File Association. This is when you associate a file extension with a default program. So when you double click a file with that extension it will open with the specified program.

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    87

    Re: [2005] Open your program by opening a file

    Yes thats correct and how i must program what to do with the file.
    Like is there a standard method called OpenWhenProgStarts(filename as string) or something? What i must do in my code to use that file(i know how to work with streams(readers/writers) etc. (or with more file names)

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] Open your program by opening a file

    what type of file is it?

    what would you do with the file if you opened it from within the program, instead of the program being started because you've chose to run the file?

    it is possible to use the main sub with args in vb.net

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Open your program by opening a file

    You would do it with the File Types editor in your setup project for deployment.
    http://msdn2.microsoft.com/en-us/lib...k6(VS.80).aspx
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    87

    Re: [2005] Open your program by opening a file

    Quote Originally Posted by .paul.
    what type of file is it?

    what would you do with the file if you opened it from within the program, instead of the program being started because you've chose to run the file?

    it is possible to use the main sub with args in vb.net
    I would do exactly the same when i open the file inside my program.

    And it doesnt matter what file type it is. I just want to know how to do it, even when its just plain text shown in a message box and after that close the program when i open that file.

    How to use this Main sub with args[] in vb.net?

    Greets

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Open your program by opening a file

    Using the Args in the Main wont make it so that when you double click on your file extension it will open in your app.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    87

    Re: [2005] Open your program by opening a file

    Then what is ?

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Open your program by opening a file

    See the link I posted in #5.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Question Re: [2005] Open your program by opening a file

    Quote Originally Posted by RobDog888
    See the link I posted in #5.
    what about for debugging + testing it?

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Open your program by opening a file

    For testing you should use Virtual PC 2007. Then you can install / uninstall til the cows come home without affecting your system install.

    To view your settings for file types just click (within the Setup project) View > File Types
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    87

    Re: [2005] Open your program by opening a file

    Well doeing it with a setup project is an other story.
    On that link you gave me there is no sample code or module i need to reference to or something like that.

    All i need to know is what code i need to write within my project to do this.
    Ill ask my question in an other way then:
    I have a file called: my.msgbox and an .exe called show.exe.
    When i drag my.msgbox to my show.exe which method i need to implement or what code i need to show the the text(that is inside my.msgbox) in a message box.

    Deploying with a setup will be the next step but first i want to know this.
    (Maybe it can be found on that link but i cant)

    Greets

  13. #13

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    87

    Re: [2005] Open your program by opening a file

    Ok i found it.
    It was very simple ^^.
    vb Code:
    1. Public Module File_assosiation ' (this is your exe name)
    2.     Public Sub Main(ByVal args() As String)
    3.         If args.Length > 0 Then
    4.             MsgBox(args(0))
    5.         Else
    6.             MsgBox("no file")
    7.             'System.Diagnostics.Process.Start(args(0))
    8.         End If
    9.     End Sub
    10. End Module

    So thnx for helo anyway

    Greets

  14. #14
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: [2005] Open your program by opening a file

    Quote Originally Posted by ovanwijk
    Ok i found it.
    It was very simple ^^.
    vb Code:
    1. Public Module File_assosiation ' (this is your exe name)
    2.     Public Sub Main(ByVal args() As String)
    3.         If args.Length > 0 Then
    4.             MsgBox(args(0))
    5.         Else
    6.             MsgBox("no file")
    7.             'System.Diagnostics.Process.Start(args(0))
    8.         End If
    9.     End Sub
    10. End Module

    So thnx for helo anyway

    Greets
    You can forget all that, use this:
    Code:
    Dim Args() As String = Environment.GetCommandLineArgs
    For Each Arg As String In Args
      'I usually use a SELECT CASE here, forcing Arg to be all lower case
    Next Arg
    This code can be used anywhere in the project, even the Load event of your startup form, this way you don't have to use a Sub Main, if you don't want to
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

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