SPFieldWorkflowStatus.GetFieldValueAsText 方法
将字段值转换为文本字符串。
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public Overrides Function GetFieldValueAsText ( _
value As Object _
) As String
用法
Dim instance As SPFieldWorkflowStatus
Dim value As Object
Dim returnValue As String
returnValue = instance.GetFieldValueAsText(value)
public override string GetFieldValueAsText(
Object value
)
参数
value
类型:System.Object一个代表的字段值的对象。
返回值
类型:System.String
32 位整数的字符串表示形式。
备注
当您直接访问字段时,键入Object返回的字段值。可以使用GetFieldValueAsText方法将原始字段值转换为相应的状态文本。
多选字段,和每个选项中的工作流模板定义,则表示状态WorkflowStatus字段。通过调用该模板的GetStatusChoices方法或通过访问SPFieldWorkflowStatus对象的Choices属性,您可以获取状态选项列表。
下表列出了三态工作流的状态选项。
域值 |
状态文本 |
---|---|
0 |
正在启动 |
1 |
启动时失败 |
2 |
进行中。 |
3 |
出现错误 |
4 |
Canceled |
5 |
已完成 |
6 |
启动 (重试) 失败 |
7 |
发生错误 (正在重试) |
示例
下面的示例是一个控制台应用程序,它采用列表中的项、 访问该项目,该WorkflowStatus字段并打印字段和相应的状态文本的这两个的原始值。
应用程序假定网站具有一个名为"Test List"列表和列表具有至少一个工作流关联和一个列表项。
Imports System
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Workflow
Module ConsoleApp
Sub Main()
Using site As SPSite = New SPSite("https://localhost")
Using web As SPWeb = site.OpenWeb()
Dim listName As String = "Test List"
Dim list As SPList = web.Lists(listName)
Dim association As SPWorkflowAssociation = list.WorkflowAssociations(0)
Dim fieldName As String = association.Name
Dim statusField As SPFieldWorkflowStatus = _
CType(list.Fields.GetField(fieldName), SPFieldWorkflowStatus)
' Get the first item in the list.
Dim item As SPListItem = list.Items(0)
' Get the value of the WorkflowStatus field.
Dim value As Object = item(fieldName)
' Print the field value and corresponding text.
Console.WriteLine("The value of the field is {0}, which means '{1}'.", _
value.ToString(), statusField.GetFieldValueAsText(value))
End Using
End Using
Console.Write(vbCrLf + "Press ENTER to continue...")
Console.ReadLine()
End Sub
End Module
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
namespace Test
{
class ConsoleApp
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("https://localhost"))
{
using (SPWeb web = site.OpenWeb())
{
string listName = "Test List";
SPList list = web.Lists[listName];
SPWorkflowAssociation association = list.WorkflowAssociations[0];
string fieldName = association.Name;
SPFieldWorkflowStatus statusField =
list.Fields.GetField(fieldName) as SPFieldWorkflowStatus;
// Get the first item in the list.
SPListItem item = list.Items[0];
// Get the value of the WorkflowStatus field.
object value = item[fieldName];
// Print the field value and corresponding text.
Console.WriteLine("The value of the field is {0}, which means '{1}'.",
value.ToString(), statusField.GetFieldValueAsText(value));
}
}
Console.Write("\nPress ENTER to continue...");
Console.ReadLine();
}
}
}
应用程序打印到控制台中的以下文本类似。(异的第一个列表项上的工作流状态输出)。
The value of the field is 2, which means 'In Progress'.
Press ENTER to continue...