/* * REFERENCE: * https://www.joe0.com/2019/01/27/how-create-a-custom-browser-uri-scheme-and-c-protocol-handler-client-that-supports-opening-and-editing-of-remotely-hosted-documents-through-webdav/ */ using System; using System.Diagnostics; using System.IO; namespace LocalExplorer { class Program { static void Main(string[] args) { //Check to make sure a path was passed in as an argument to the program. if (args.Length == 0) { Console.WriteLine("usage: LocalExplorer.exe "); WriteOutputFile("no args passed to program"); Environment.Exit(1); } //Collect up the path //the replace function is here to trim out the arg as it //comes in from the url protocol handler string path = args[0].Replace("localexplorer:", "").Replace("%5C", "\\"); ; WriteOutputFile($"arg passed: {path}"); //Check to see if the directory exists. //if so, pop it open. if (Directory.Exists(path)) { ProcessStartInfo startInfo = new ProcessStartInfo { Arguments = path, FileName = "explorer.exe" }; Process.Start(startInfo); } else { WriteOutputFile($"Directory does not exist: {path}"); Console.WriteLine("Directory does not exist."); } } //end main private static void WriteOutputFile(string debugLine) { return; // remove the above return for debugging StreamWriter outFile = new StreamWriter(@"C:\LocalExplorer\OUTPUT.txt", true); outFile.WriteLine(debugLine); outFile.Close(); } } }