Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 475
  • Last Modified:

open custom file on double click (file association)

Hi Experts!
I need a piece of code in order to open a text file with a custom extension, ie: .xyz (Already associated with my app via setup)
I need the file to be loaded in a text box on my main form when the user double clicks on any file with that extension.
Help will be very appreciated.
Thanks in advance.
0
jorgemgonzalez
Asked:
jorgemgonzalez
  • 3
  • 2
1 Solution
 
käµfm³d 👽Commented:
When you double-click a file, its path is passed to its associated executable as a parameter. Think of it like opening up a command prompt and doing something like:

    C:\path\to\my\executable.exe C:\path\to\some\file.txt

As such, you can interrogate the command line arguments for your application and open the first argument as a text file, read it, then display the text however you like--in this case, put it in your textbox.
0
 
käµfm³d 👽Commented:
0
 
gamarrojgqCommented:
Hi,

Try this, if your file contains no readable data, you will be able to see it in the textbox (assuming you have a textbox named textbox1)

        Dim strFile As String

        strFile = Command()
        strFile = strFile.Replace("""", "")

        Dim srdFile As New StreamReader(strFile)
        textbox1.Text = srdFile.ReadToEnd
        srdFile.Close()
        srdFile.Dispose()
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
jorgemgonzalezAuthor Commented:
Quick and excellent solution, much appreciated.
0
 
jorgemgonzalezAuthor Commented:
I also want to thank gamarrojgq: for the fast reply.
0
 
käµfm³d 👽Commented:
NP. Glad to help :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now