Click here to Skip to main content
15,071,637 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
I have Created A Notepad ! And I know How to make it the Default Opening Program for *.txt Files. (using Registry key)So When I double click on a text file on my computer I want to Read that using my program. Please Answer ! Add The Code ! Please !
Updated 1-Dec-11 5:58am
Manoj K Bhoir 1-Dec-11 9:49am
If you know how to make your application Default editor through registry then do it through code or provide registry key which are required to change i will give you the code.
Captain Price 1-Dec-11 11:00am
Thank you ! It will be really helpful for me ! So ?
Richard MacCutchan 1-Dec-11 11:08am
If you know how to do it then what extra help do you need?
Captain Price 1-Dec-11 11:32am
um, I Only Know a part of it. Nothing Beyond that ! Do you know the Code ? pls
No, you did not create Notepad. Notepad was created by Microsoft and is ridiculously rudimentary, almost unusable. Who need another one? If you did not create anything better, through it out. If you did, give it a proper name.

It's pretty easy to find a solution. Why did not you do it so far, just looking at Registry and using Google? Any particular problem?

For example, you will find explanation and further references here:[^].


Please see my comment below. Your changes in the Registry only provides the Shell with relevant information. It effects the use of related API in the code. In particular, use can simply call:


Can you see? The application is not specified, just the data file. Nevertheless, as the Shell is involved here, it will find out the data about processing of "*.txt" files and will start your application as
YourApplication.exe myDocument.txt

(with full path name of the application, of course).

However, you will need one more thing: you application should process command line and load the file according to it. If you did not do it so far, it won't work.

For processing of command line, you can use a comprehensive solution I offer in my article (don't worry, easy to use): Enumeration-based Command Line Utility[^]. There is a reference to one more solution in my article's text.

Captain Price 1-Dec-11 11:57am
Thank you for your solution.
So, it's all about system registry, Isn't it ?
Absolutely. Even though it's in more than one key (for a new "file type"), this does not affect the whole system, only provides relevant information to the Shell and could be used directly in the call... I'll explain.
So, please see more information in my updates solution, after [EDIT].
Captain Price 2-Dec-11 3:38am
Sorry, it's hard to understand your article !! Can you give me the Exact Code for the question. pls
Complete Solution For This Question By The Asker

In this case, we have to get the use of system registry. So You Must create a Registry Key (information about your software in windows) in windows registry.

Step 01 - Creating A Key

1.Create a Windows Application Named 'MyTextEditor' using VB.NET
2.Add a button to the application (usually form1), give it a text as 'Create a Key.
3. Double Click on the button and Add The Following Code

My.Computer.Registry.ClassesRoot.OpenSubKey("txtfile\shell\open\command\", True).SetValue("", Application.ExecutablePath & " ""%l"" ", Microsoft.Win32.RegistryValueKind.String)

Note ! Now, When you Double Click on a Text File, it opens your program, But it don't show any text from the text file

Step 02 - Using the Key

1. Open the windows application project you created earlier.
2. In it's form Load event add the following piece of code.

     MsgBox("Hello, " & My.Computer.FileSystem.ReadAllText(My.Application.CommandLineArgs(0)) & " World!")

  Catch ex As Exception

End Try

3. Build Your Project

Step 03 - See How it is Working

1. Open the Application that you build('myTextEditor.exe')
Note ! You Must Open the Program as the Administrator to Work

2. Click on the button.
3. Close the Program.
4. Open a text file on your Computer. Now you'll see the text of that file in a message box.

Additional Information

Read the Following Articles for advanced purposes ;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900