ProcessStartInfo.Verb 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置打开 FileName 属性指定的应用程序或文档时要使用的谓词。
public:
property System::String ^ Verb { System::String ^ get(); void set(System::String ^ value); };
public string Verb { get; set; }
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.VerbConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string Verb { get; set; }
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.VerbConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string Verb { get; set; }
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.VerbConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string Verb { get; set; }
member this.Verb : string with get, set
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.VerbConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.Verb : string with get, set
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.VerbConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.Verb : string with get, set
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.VerbConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.Verb : string with get, set
Public Property Verb As String
属性值
要对进程打开的文件执行的操作。 默认值为空字符串 (""),它表示没有操作。
- 属性
示例
下面的代码示例使用指定的谓词和文件名启动新进程。 此代码示例是为 属性提供的更大示例的 Verbs 一部分。
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;
}
Dim i = 0
Dim startInfo = New ProcessStartInfo(fileName)
Dim verb As String
For Each verb In startInfo.Verbs
' Display the possible verbs.
Console.WriteLine($" {i}. {verb}")
i += 1
Next
Console.Write("Select the index of the verb: ")
Dim indexInput = Console.ReadLine()
Dim index As Integer
If Int32.TryParse(indexInput, index) Then
If index < 0 OrElse index >= i Then
Console.WriteLine("Invalid index value.")
Return
End If
Dim verbToUse = startInfo.Verbs(Convert.ToInt32(index))
startInfo.Verb = verbToUse
If verbToUse.ToLower().IndexOf("printto") >= 0 Then
' printto implies a specific printer. Ask for the network address.
' The address must be in the form \\server\printer.
Console.Write("Enter the network address of the target printer: ")
Dim arguments = Console.ReadLine()
startInfo.Arguments = arguments
End If
注解
每个文件扩展名都有其自己的谓词集,可以使用 属性获取 Verbs 这些谓词。 例如,“”print
谓词将打印使用 FileName指定的文档。 可以使用空字符串 (“”) 指定默认谓词。 动词的示例包括“Edit”、“Open”、“OpenAsReadOnly”、“Print”和“Printto”。 应仅使用显示在 属性返回的谓词集中的 Verbs 谓词。
使用 Verb 属性时,在设置 属性的值 FileName 时必须包含文件扩展名。 如果手动为 属性输入值 Verb ,则文件名不需要具有扩展名。