Does the handle open with the help open?

Possible duplicate:
C # Windows 'Open With>' Context Menu Behavior

How should I do it? For example, if I right-click on a file and open it, then my program, as I do the material in this file: /.

+3
source share
2 answers

I use the following code to pass the first argument (the one that contains the file name) to my gui application:

static class Program {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args) {

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(args.Length == 0 ? new Form1(string.Empty) : new Form1(args[0]));
        }
    }

I check if there is an argument. If not, and the user runs your program without it, you can get an exception in any code that tries to use it.

This is a snippet from my Form1 that processes the input file:

public Form1(string path) {
    InitializeComponent();

    if (path != string.Empty && Path.GetExtension(path).ToLower() != ".bgl") {
        //Do whatever
    } else {
        MessageBox.Show("Dropped File is not Bgl File","File Type Error",      MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        path = string.Empty;
    }
    //.......
}

, - -.bgl - , , . . ( ),

, . .

+6

. .

:

  • - args, , Main:

    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FormMain());
        }
    }
    
  • - Environment.GetCommandLineArgs. , , Main.

+2

All Articles