Search code examples
c#file-associationprocessstartinfo

Get List of available Verbs (file association) to use with ProcessStartInfo in c#


I am trying to open and print files with the ProcessStartInfo class. (File can be anything but let`s assume it is a PDF File)

  ProcessStartInfo pi = new ProcessStartInfo(file);
  pi.Arguments = Path.GetFileName(file);
  pi.WorkingDirectory = Path.GetDirectoryName(file);
  pi.Verb = "OPEN";  
  Process.Start(pi);

this works well for the pi.Verb = "OPEN";. Some applications register themselves also with the verb "PRINT" but only some do. In my case (Windows PDF Viewer) I get an exception when trying to execute with the pi.Verb = "PRINT";

Is there a way to see all the verbs available for a specific type in C# at runtime?

Thx a lot


Solution

  • From MSDN: https://msdn.microsoft.com/en-us/library/65kczb9y(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2

     startInfo = new ProcessStartInfo(fileName);
    
        if (File.Exists(fileName))
        {
            i = 0;
            foreach (String verb in startInfo.Verbs)
            {
                // Display the possible verbs.
                Console.WriteLine("  {0}. {1}", i.ToString(), verb);
                i++;
            }
        }