Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I have created a simple notepad application.
I have deployed it in my system by creating setup file for that app.
But , only one problem is that

generally we open a file in this way


right click a file -> open with -> choose the program with which we want to open the file.


then the file will be loaded into the richtextBox field provided in the app.

Can any one suggest me what is the code i have to add to get the file loaded as we open the file?????
Posted
Comments
Jibesh 13-Dec-12 16:21pm    
Your question is not clear. where you are stuck?
dont know how to read a file ?
what type of file is that?
what are all the extensions your application does support?

"generally we open a file in this way
right click a file -> open with -> choose the program with which we want to open the file."

Not necessarily .. I double click on the file at times and it loads on the editor associated with that file extension
Sergey Alexandrovich Kryukov 13-Dec-12 17:16pm    
You considerations about "right click a file" make me think that this is off-topic. This is a forum for software developers. From programmatic standpoint, you don't "click a file", like a (possibly lamer) user... :-)
--SA

This is System.Windows.Forms.RichTextBox.LoadFile: http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.loadfile.aspx[^].

—SA
 
Share this answer
 
C#
System.Windows.Forms.RichTextBox.LoadFile(FileName, RichTextBoxStreamType);
 
Share this answer
 
To make this right-click-open-with-approach work, you need to process command-line parameters to your program. If it has been called by the operating system with the intent to open a file, the OS will
1. have called your executable and
2. have appended the path to the file as parameter.

Use the Environment.GetCommandLineArgs()[^] method to get all the arguments that your executable has been called with and check if the first one is a file that you can open. If so, then open it just like you would do after user clicks File - Open - [filename] from within your application.
 
Share this answer
 
v2
 
Share this answer
 

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