how to open ur custom file format in ur application

hi,
i am developing an application in C#.For saving the state of an application i am using a
custom file format.Now suppose a user using the application want to save the state of the application he can save it as "savedstate.abcd" where .abcd is the new extension to be supported by my application.Now when he double clicks on this saved file named "savedstate.abcd" my application will open up and the objects being used in my application will be instantiated with the saved data.

i have done addition in the registry so than when a user double clicks file with my extension ".abcd" the application will start.but how do i read the application state from my saved file because my application does not know on which file the user clicked.

i need to connect to file on which the user double clicked so as to read the information from it......how can i do it.

please help or point me in some direction where i can lookout on my own.

regards
Ramneek



Answer this question

how to open ur custom file format in ur application

  • Patrick8

    hi vikram ,thanks it worked.
    thanks to jmcilhinney also.
    regards
    Ramneek

  • JustinCase864

    I just came back to mention that you can use the Environment.GetCommandLineArgs function as well.  I've not tried it but you may not even have to use a Main method.  Just call Environment.GetCommandLineArgs in the main form's constructor or Load event handler, wherever is more appropriate.
  • Gioking

    Hi,

    I am assuming you have already registered the extension with ur application.

    In that case when you doubleclick on say Sample.abcd in C:\Temp, then the args[0] will have a string that has the complete path to the file including the filename.
    args[0] will have the value "C:\Temp\Sample.abcd".

    Let me know if you need more clarifications.

    Regards,
    Vikram

  • GSA

    I believe that when your app is initiated in this way the file name will be the first commandline argument, so you would need to write your Main method to deal with this.

  • krishna kishore

    Thats right. You get the FilePath as a parameter to the Main method.
    So you would need to write your main method as follows if u are using a Windows Forms application:


    [STAThread]
      static void Main(string[] args)
      {
       if (args.Length > 0)
        Application.Run(new Form1(args[0]));
       else    
        Application.Run(new Form1());
      }

     


    And also you would need to add a separate constructor to your Form, which starts up to capture the value.

    Regards,
    Vikram



  • Claire O

    ok.i can write the command line argument in main but how to pass the name of the file on which double click or some other action was performed...how to provide for connectivity between my main function with arguments and my custom file.that is what i was wondering how to do
  • Domer

    but how to pass the filepath to the main function..
    regards
    ramneek

  • how to open ur custom file format in ur application