none
c# Get path of selected file with Context Menu to MyApp? RRS feed

  • Question

  • Hello everyone,
    I added the MyApp to the Context Menu (for .exe file only).
    (This works, when I click on MyApp on Context Menu, MyApp are opens.)

    private void addContextMenu()
            {
                Microsoft.Win32.RegistryKey rkey;
                rkey = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey("exefile\\Shell\\MyApp");
                rkey.SetValue("", "MyApp");
                rkey.SetValue("icon", "C:\\Program Files\\MyApp\\MyApp.exe,0");
    
                Microsoft.Win32.RegistryKey rkey1;
                rkey1 = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey("exefile\\Shell\\MyApp\\command");
                rkey1.SetValue("", "C:\\Program Files\\MyApp\\MyApp.exe" + " \"%1\"";
                rkey1.Close();
            }

    I would like, when I click on MyApp on Context Menu:

    1. MyApp are opens. (it already works)
    2. Get the path of the selected file (.exe) to the textBox1.Text on MyApp.

    If it's possible, how can I do it?
    I ask for your answer. Thank you.


    • Edited by ZoAndrea Friday, April 6, 2018 7:19 PM
    Friday, April 6, 2018 7:17 PM

Answers

  • May This Help You

    Change Program.cs startup static class to take arguments & pass to form

        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 Form1(args));
    
            }
        }
    Overload form constructor to display path
     public Form1(string[] args)
            {
                InitializeComponent();
                //addContextMenu();
                if (args.Length>0)
                {
                    textBox1.Text = Path.GetDirectoryName(args[0]);      //Folder Path of .exe file
                    //textBox1.Text = args[0];           //Full Path Including .exe file } }
    Best Regards
    Vikram Manjare
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.





    • Edited by Vikram Manjare Friday, April 6, 2018 7:47 PM
    • Marked as answer by ZoAndrea Friday, April 6, 2018 8:20 PM
    Friday, April 6, 2018 7:39 PM

All replies

  • May This Help You

    Change Program.cs startup static class to take arguments & pass to form

        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 Form1(args));
    
            }
        }
    Overload form constructor to display path
     public Form1(string[] args)
            {
                InitializeComponent();
                //addContextMenu();
                if (args.Length>0)
                {
                    textBox1.Text = Path.GetDirectoryName(args[0]);      //Folder Path of .exe file
                    //textBox1.Text = args[0];           //Full Path Including .exe file } }
    Best Regards
    Vikram Manjare
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.





    • Edited by Vikram Manjare Friday, April 6, 2018 7:47 PM
    • Marked as answer by ZoAndrea Friday, April 6, 2018 8:20 PM
    Friday, April 6, 2018 7:39 PM
  • Thank you, Vikram, it is work.


    • Edited by ZoAndrea Friday, April 6, 2018 8:21 PM
    Friday, April 6, 2018 8:09 PM