This tutorial will demonstrate you how to associate an extension with your application and reading its contents.
Basically there are two ways of doing this. 1st is through API but that is pretty much advanced. 2nd way of doing this is using registry to simply create an extension for your program in the root class and adding the arguments for it. So we will use registry since it does the same as API.
Let's start:
1: Create a new project.
2: Go to code of the main form.
3: Create a sub-procedure named "AddToRegistry" that can accept 1 parameter of String data type. Add the following code in it:
Where "extension" is the parameter the sub-procedure will accept.
What the procedure does is, it creates a new key for your extension. Then it creates sub keys for it that windows actually recognizes. That are: "Shell", "Open" and "Command" respectively.
Inside the command we set the default value to the path of our application's executable file.
Now we need at least one parameter that our application can read. To read the contents of a file, you can use windows predefine parameter "%l". What it does is that it returns the address of the file you've just opened. So when your application loads it, it can read its contents successfully.
If you want more than 1 parameter, just give a space and add it in a double quote.
4: Now double click the Form to go to the Form's load event. Inside the form's load event enter the following code:
[php]'This will associate the entention to your application.
AddToRegistry()
'Here you catch the arguments you just specified...
For Each Argument As String In My.Application.CommandLineArgs
Dim ReadContent As String = My.Computer.FileSystem.ReadAllText(Argument)
'Just read it and display it in a textbox or message box.
rtb.Text = ReadContent
'If you just want to read the contents then exit Loop
Exit For
Next
[/php] Now write some sample text in notepad and save it as your extension.
Now run the code (Application). And then close it. Now double click the new file you created and it will open in your application and also will read everything written in it.