2

I have an application which relies on being called by a custom URL protocol; for reference see this post. The registry link works, but when I try to catch passed parameters from the URL (e.g. I launch customurl://param1=xy&param2=xy in a browser) I seem to fail it with the code below;

Program.cs

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

Form1.cs

public Form1(string[] args) {
    [...]
    if (args.Length > 0) {
        string name = args[0];
        label1.Text = "received paramter: " + name;
    } else {
        label1.Text = "no received parameter!";
    }
}

The condition always chooses the else branch, which means the args[] array contained none of the passed parameters. What am I doing wrong? Is there another specific method to catch parameters given these conditions?

EKOlog
  • 410
  • 7
  • 19
Viktor
  • 153
  • 1
  • 13
  • Not sure if this is a typo, but you seem to have forgotten to denote the start of the GET query using `?`. Your URL should be `customurl://?param1=xy&param2=xy` – thebugsdontwork Oct 27 '21 at 14:35
  • @ogjtech it was not a typo, but the result is the same unfortunately – Viktor Oct 27 '21 at 14:37
  • Try taking separate variable instead of args array in forms1 method as parameter and make sure your url looks like `customurl?param1=xy&param2=xy` – Shafiqul Bari Sadman Oct 27 '21 at 14:30

1 Answers1

2

The behavior you observe can be caused by forgetting the "%1" in the registry. "%1" is a placeholder for the URL. If you forget to include it, the URL won't get passed to your handler.

Here is another SE post with similar instructions How do I register a custom URL protocol in Windows? It shows you exactly where you need to put the "%1".

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109