Is there any way to detect when a file is opened with a c# application
Example When I right-click on a file then select to open it with My Application I want this code to run
File.WriteLines(OpenWithFile)
Is this achievable
Is there any way to detect when a file is opened with a c# application
Example When I right-click on a file then select to open it with My Application I want this code to run
File.WriteLines(OpenWithFile)
Is this achievable
Yes, it's achievable. When a user clicks Open With in Windows Explorer, the operating system includes the filename as the first argument. Below is a demo how you'd get the file name that the user clicked to open with your application. You can than implement whatever processing you wish.
class Program
{
static void Main(string[] args)
{
if (args.Length > 0)
{
var OpenWithFile = args[0];
Console.WriteLine($"The OpenWithFile is: {OpenWithFile}");
}
else
{
Console.WriteLine("No command-line arguments were passed.");
}
Console.WriteLine("Press any key to continue.");
Console.ReadLine();
}
}