Marc Wittmann Marc Wittmann - 1 year ago 163
C# Question

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";

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

Answer Source

From MSDN:

 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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download