Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. New Editor

New Editor

Scheduled Pinned Locked Moved C#
questiontutorial
15 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GunaChinna
    wrote on last edited by
    #1

    Requirement: I want to create an application, which should be able to create a file, with the file extension be specified by me. And, when i double click to open that file, it should open it's content in that application. How can this be achieved? ( like word,excel..etc) Code so far: For example.. I have created a application with a Richtextbox control to display data,buttons to create a new file, openfile,savefile and to exit. And let my file extension be ".gun". Time to Answer: Now, what happens is i create new file, save(savefiledialog) it with .gun extension. This files gets opened when i open it using 'open(openfiledialog) button' which is present in my application. But when i double this file (which is placed on desktop) it opens only the application and not with the content.? How can i get it with the content when the file is double clicked?

    L M G 3 Replies Last reply
    0
    • G GunaChinna

      Requirement: I want to create an application, which should be able to create a file, with the file extension be specified by me. And, when i double click to open that file, it should open it's content in that application. How can this be achieved? ( like word,excel..etc) Code so far: For example.. I have created a application with a Richtextbox control to display data,buttons to create a new file, openfile,savefile and to exit. And let my file extension be ".gun". Time to Answer: Now, what happens is i create new file, save(savefiledialog) it with .gun extension. This files gets opened when i open it using 'open(openfiledialog) button' which is present in my application. But when i double this file (which is placed on desktop) it opens only the application and not with the content.? How can i get it with the content when the file is double clicked?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Look for method "Main" in your application. If you have no parameters in it "Main()" then change it to "Main(string[] args)". If you double-click .gun file, then it is like calling using command prompt: MyApplication.exe myFile.gun Just take your .gun file in "args" variable.

      B 1 Reply Last reply
      0
      • G GunaChinna

        Requirement: I want to create an application, which should be able to create a file, with the file extension be specified by me. And, when i double click to open that file, it should open it's content in that application. How can this be achieved? ( like word,excel..etc) Code so far: For example.. I have created a application with a Richtextbox control to display data,buttons to create a new file, openfile,savefile and to exit. And let my file extension be ".gun". Time to Answer: Now, what happens is i create new file, save(savefiledialog) it with .gun extension. This files gets opened when i open it using 'open(openfiledialog) button' which is present in my application. But when i double this file (which is placed on desktop) it opens only the application and not with the content.? How can i get it with the content when the file is double clicked?

        M Offline
        M Offline
        Mark Porter
        wrote on last edited by
        #3

        You will need to associate the file extension *.gun with your application - the article http://support.microsoft.com/kb/185453 describes for VB but its basicallyde sticking some info in the registry...

        1 Reply Last reply
        0
        • L Lost User

          Look for method "Main" in your application. If you have no parameters in it "Main()" then change it to "Main(string[] args)". If you double-click .gun file, then it is like calling using command prompt: MyApplication.exe myFile.gun Just take your .gun file in "args" variable.

          B Offline
          B Offline
          bobsugar222
          wrote on last edited by
          #4

          Or just call Environment.GetCommandLineArgs()

          1 Reply Last reply
          0
          • G GunaChinna

            Requirement: I want to create an application, which should be able to create a file, with the file extension be specified by me. And, when i double click to open that file, it should open it's content in that application. How can this be achieved? ( like word,excel..etc) Code so far: For example.. I have created a application with a Richtextbox control to display data,buttons to create a new file, openfile,savefile and to exit. And let my file extension be ".gun". Time to Answer: Now, what happens is i create new file, save(savefiledialog) it with .gun extension. This files gets opened when i open it using 'open(openfiledialog) button' which is present in my application. But when i double this file (which is placed on desktop) it opens only the application and not with the content.? How can i get it with the content when the file is double clicked?

            G Offline
            G Offline
            GunaChinna
            wrote on last edited by
            #5

            Hi, When i use Main(string[] args) or Environment.GetCommandLineArgs; it shows me the following error. Error 1 'string' does not contain a definition for 'rtbFile' (Richtextbox instance)

            B 1 Reply Last reply
            0
            • G GunaChinna

              Hi, When i use Main(string[] args) or Environment.GetCommandLineArgs; it shows me the following error. Error 1 'string' does not contain a definition for 'rtbFile' (Richtextbox instance)

              B Offline
              B Offline
              bobsugar222
              wrote on last edited by
              #6

              show us the code.

              G 1 Reply Last reply
              0
              • B bobsugar222

                show us the code.

                G Offline
                G Offline
                GunaChinna
                wrote on last edited by
                #7

                The error is ok now. and i have done main(string[] args) or Environment.GetCommandLineargs..... But still when i double click the created file(file with .gun extension),, it still doesn't contain the content.

                L 1 Reply Last reply
                0
                • G GunaChinna

                  The error is ok now. and i have done main(string[] args) or Environment.GetCommandLineargs..... But still when i double click the created file(file with .gun extension),, it still doesn't contain the content.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Just for example :

                  static void Main(string[] args)
                  {
                  string fileToOpen = args[0]; // it is the same like openFileDialog.FileName

                  // Now you MUST open the file "fileToOpen"
                  }

                  G 1 Reply Last reply
                  0
                  • L Lost User

                    Just for example :

                    static void Main(string[] args)
                    {
                    string fileToOpen = args[0]; // it is the same like openFileDialog.FileName

                    // Now you MUST open the file "fileToOpen"
                    }

                    G Offline
                    G Offline
                    GunaChinna
                    wrote on last edited by
                    #9

                    I dont get what u try to say. This is my code. Can u suggest with this code....(ofdFile=Openfiledialog,rtbFile=richtextbox) void btnOpen_Click(object sender, EventArgs e) { ofdFile = new OpenFileDialog(); ofdFile.DefaultExt = @"*.gun"; ofdFile.Filter = @"Gun Files|*.gun"; if (ofdFile.ShowDialog() == System.Windows.Forms.DialogResult.OK && ofdFile.FileName.Length > 0) { //ofdFile.FileName. rtbFile.LoadFile(ofdFile.FileName, RichTextBoxStreamType.PlainText); } }

                    G L 2 Replies Last reply
                    0
                    • G GunaChinna

                      I dont get what u try to say. This is my code. Can u suggest with this code....(ofdFile=Openfiledialog,rtbFile=richtextbox) void btnOpen_Click(object sender, EventArgs e) { ofdFile = new OpenFileDialog(); ofdFile.DefaultExt = @"*.gun"; ofdFile.Filter = @"Gun Files|*.gun"; if (ofdFile.ShowDialog() == System.Windows.Forms.DialogResult.OK && ofdFile.FileName.Length > 0) { //ofdFile.FileName. rtbFile.LoadFile(ofdFile.FileName, RichTextBoxStreamType.PlainText); } }

                      G Offline
                      G Offline
                      GunaChinna
                      wrote on last edited by
                      #10

                      And my main function is in Program.cs file

                      1 Reply Last reply
                      0
                      • G GunaChinna

                        I dont get what u try to say. This is my code. Can u suggest with this code....(ofdFile=Openfiledialog,rtbFile=richtextbox) void btnOpen_Click(object sender, EventArgs e) { ofdFile = new OpenFileDialog(); ofdFile.DefaultExt = @"*.gun"; ofdFile.Filter = @"Gun Files|*.gun"; if (ofdFile.ShowDialog() == System.Windows.Forms.DialogResult.OK && ofdFile.FileName.Length > 0) { //ofdFile.FileName. rtbFile.LoadFile(ofdFile.FileName, RichTextBoxStreamType.PlainText); } }

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        pass the args[0] to your form class.

                        static void Main(string[] args)
                        {
                        Application.Run(new Form1(args[0]));
                        }

                        For example your form class is Form1. Then change the constructor to

                        public Form1(string fileToBeOpened)
                        {
                        if(fileToBeOpened != string.Empty)
                        {
                        // rtbFile.LoadFile(fileToBeOpened , RichTextBoxStreamType.PlainText);
                        }
                        }

                        G 1 Reply Last reply
                        0
                        • L Lost User

                          pass the args[0] to your form class.

                          static void Main(string[] args)
                          {
                          Application.Run(new Form1(args[0]));
                          }

                          For example your form class is Form1. Then change the constructor to

                          public Form1(string fileToBeOpened)
                          {
                          if(fileToBeOpened != string.Empty)
                          {
                          // rtbFile.LoadFile(fileToBeOpened , RichTextBoxStreamType.PlainText);
                          }
                          }

                          G Offline
                          G Offline
                          GunaChinna
                          wrote on last edited by
                          #12

                          It shows me 'IndexOutOfRangeException Unhandled' in program.cs Application.Run(new Form1(args[0]));

                          L 1 Reply Last reply
                          0
                          • G GunaChinna

                            It shows me 'IndexOutOfRangeException Unhandled' in program.cs Application.Run(new Form1(args[0]));

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #13

                            I think you just COPY and PASTE the code. You must AWARE OF ERRORS. You MUST check if args.Length > 0 // you get the file directly args.Length == 0 // without file

                            G 1 Reply Last reply
                            0
                            • L Lost User

                              I think you just COPY and PASTE the code. You must AWARE OF ERRORS. You MUST check if args.Length > 0 // you get the file directly args.Length == 0 // without file

                              G Offline
                              G Offline
                              GunaChinna
                              wrote on last edited by
                              #14

                              Yes it works. Thanks a lot.

                              G 1 Reply Last reply
                              0
                              • G GunaChinna

                                Yes it works. Thanks a lot.

                                G Offline
                                G Offline
                                GunaChinna
                                wrote on last edited by
                                #15

                                Will get u back if i get more doubts.

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups