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¶m2=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>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
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.