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¶m2=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?
CodePudding user response:
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"
.