How to get the params values from the URL scheme which is registered in registry

Dineshkumar.S 446 Reputation points

I'm trying to start my C# app from a url (example "myapp:?param1=something&param2=somethingelse") and I've been able to do that, however I still can't understand how to read the "something" and "somethingelse" value that the url should pass to the app. can anyone please do give ideas to do that? Thanks in advance

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,937 questions
0 comments No comments
{count} votes

Accepted answer
  1. Reza Aghaei 4,931 Reputation points MVP

    Assuming you have opened the app from URL using your custom URL scheme, the command-line argument is the URL. FOr example:

    • myapp:?param1=something&param2=somethingelse

    Then add reference to System.Web assembly, create a Uri by passing the command-line arguments to it, and get its Query, then using HttpUtility.ParseQueryString get all the query string parameters.

    Here is the example:

    using System;
    using System.Web;
    using System.Windows.Forms;
    namespace UrlSchemeSample
        static class Program
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            static void Main()
                var args = "";
                if (Environment.GetCommandLineArgs().Length > 1)
                    args = Environment.GetCommandLineArgs()[1];
                MessageBox.Show($"You can decide what to do with the arguments:\n{args}");
                var uri = new Uri(args);
                var query = HttpUtility.ParseQueryString(uri.Query);
                MessageBox.Show($"param1 is: {query["param1"]}");
                MessageBox.Show($"param2 is: {query["param2"]}");
                Application.Run(new Form1());

    Do not forget to add reference to System.Web dll.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful