Search code examples
.netwpfwindowsmagnet-uri

Magnet Link with .NET and WPF


I'm just looking for a sample project to get an idea for how I should implement my application.

Just like in torrent files, I want to open and fire an event in a WPF application via a Website link. How do I do this ?


Solution

  • OK. Here is how I solved it.

    1. I'm adding the registry key to register custom URL Scheme first

    Windows Registry Editor Version 5.00

    [HKEY_CLASSES_ROOT\KA] @="URL:KA Protocol" "URL Protocol"=""

    [HKEY_CLASSES_ROOT\KA\shell]

    [HKEY_CLASSES_ROOT\KA\shell\open]

    [HKEY_CLASSES_ROOT\KA\shell\open\command] @="\"C:\Users\me\Desktop\myapp\myapp.exe\" \"%1\""

    1. Typing KA://myargument in Internet Explorer to try to process myapp.exe

    2. Handling in my WPF app as this in App.cs

      public partial class App : Application
      {
          void App_Startup(object sender, StartupEventArgs e)
          {
              for (int i = 0; i != e.Args.Length; ++i)
              {
                  if (e.Args[i].StartsWith("ka:"))
                  {
                      int index = e.Args[i].IndexOf(':') +1;
                      string argg= e.Args[i].Substring(index, e.Args[i].Length - index); // handling argument here
      
                  }
              }
      
              Shell mainWindow = new Container();
              mainWindow.Show();
          }
      }