共用方式為


SPFieldWorkflowStatus.GetFieldValueAsText method

將欄位值轉換成文字字串。

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'宣告
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
)

參數

傳回值

Type: System.String
32 位元整數字串表示。

備註

當您直接存取欄位時,請鍵入Object,會傳回欄位值。您可以使用GetFieldValueAsText方法可將原始欄位值轉換成對應的狀態文字。

WorkflowStatus欄位是 multichoice] 欄位中,而每種選擇代表狀態的工作流程範本中所定義。您可以透過呼叫的範本GetStatusChoices方法或存取SPFieldWorkflowStatus物件的Choices屬性來取得狀態選擇清單。

下表列出三態工作流程狀態選項。

欄位值

狀態文字

0

啟動

1

啟動失敗

2

進行中。

3

發生錯誤

4

取消此事件

5

完成

6

啟動 (重試中) 失敗

7

錯誤發生 (重試中)

Examples

下列範例會為主控台應用程式,取得從清單中的項目、 存取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...

請參閱

參照

SPFieldWorkflowStatus class

SPFieldWorkflowStatus members

Microsoft.SharePoint namespace

GetFieldValueAsHtml(Object)