Solved

open custom file on double click (file association)

Posted on 2010-11-09
6
455 Views
Last Modified: 2012-06-27
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
Comment
Question by:jorgemgonzalez
  • 3
  • 2
6 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 34097789
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
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 34097809
0
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 34097840
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Closing Comment

by:jorgemgonzalez
ID: 34098463
Quick and excellent solution, much appreciated.
0
 

Author Comment

by:jorgemgonzalez
ID: 34098470
I also want to thank gamarrojgq: for the fast reply.
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 34098661
NP. Glad to help :)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now