ProcessStartInfo.Verb Property

Definition

Gets or sets the verb to use when opening the application or document specified by the FileName property.

C#
public string Verb { get; set; }
C#
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.VerbConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string Verb { get; set; }
C#
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.VerbConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string Verb { get; set; }
C#
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.VerbConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string Verb { get; set; }

Property Value

The action to take with the file that the process opens. The default is an empty string (""), which signifies no action.

Attributes

Examples

The following code example starts a new process by using the specified verb and file name. This code example is part of a larger example provided for the Verbs property.

C#
int i = 0;
var startInfo = new ProcessStartInfo(fileName);

// Display the possible verbs.
foreach (var verb in startInfo.Verbs)
{
    Console.WriteLine($"  {i++}. {verb}");
}

Console.Write("Select the index of the verb: ");
var indexInput = Console.ReadLine();
int index;
if (Int32.TryParse(indexInput, out index))
{
    if (index < 0 || index >= i)
    {
        Console.WriteLine("Invalid index value.");
        return;
    }

    var verbToUse = startInfo.Verbs[index];

    startInfo.Verb = verbToUse;
    if (verbToUse.ToLower().IndexOf("printto") >= 0)
    {
        // printto implies a specific printer. Ask for the network address.
        // The address must be in the form \\server\printer.
        // The printer address is passed as the Arguments property.
        Console.Write("Enter the network address of the target printer: ");
        var arguments = Console.ReadLine();
        startInfo.Arguments = arguments;
    }

    try
    {
        using (var newProcess = new Process())
        {
            newProcess.StartInfo = startInfo;
            newProcess.Start();

            Console.WriteLine($"{newProcess.ProcessName} for file {fileName} " +
                              $"started successfully with verb '{startInfo.Verb}'!");
        }
    }
    catch (Win32Exception e)
    {
        Console.WriteLine("  Win32Exception caught!");
        Console.WriteLine($"  Win32 error = {e.Message}");
    }
    catch (InvalidOperationException)
    {
        // Catch this exception if the process exits quickly,
        // and the properties are not accessible.
        Console.WriteLine($"Unable to start '{fileName}' with verb {verbToUse}");
    }
}

Remarks

Each file name extension has its own set of verbs, which can be obtained by using the Verbs property. For example, the "print" verb prints a document specified by using FileName. The default verb can be specified by using an empty string (""). Examples of verbs are "Edit", "Open", "OpenAsReadOnly", "Print", and "Printto". You should use only verbs that appear in the set of verbs returned by the Verbs property.

When you use the Verb property, you must include the file name extension when you set the value of the FileName property. The file name does not need to have an extension if you manually enter a value for the Verb property.

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also