SPFieldWorkflowStatus.Init 方法

初始化SPFieldWorkflowStatus对象。

命名空间:  Microsoft.SharePoint
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
Public Sub Init ( _
    strUrl As String, _
    strShowField As String _
)
用法
Dim instance As SPFieldWorkflowStatus
Dim strUrl As String
Dim strShowField As String

instance.Init(strUrl, strShowField)
public void Init(
    string strUrl,
    string strShowField
)

参数

  • strUrl
    类型:System.String

    自定义工作流状态页的 URL。默认值为_layouts/WrkStat.aspx。

  • strShowField
    类型:System.String

    要显示的字段的名称。默认值为Status1。

备注

此方法设置WorkflowStatusURL属性和ShowField属性字段元素定义,并将该字段的ReadOnlyField属性设置为true。

示例

以下示例将WorkflowStatus字段添加到名为Test List列表一个控制台应用程序,并将字段初始化。

应用程序所需网站具有一个名为"Test List",并至少一个工作流模板列表。

Imports System
Imports System.Collections.Specialized

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 list As SPList = web.Lists("Test List")
            Dim workflowTemplate As SPWorkflowTemplate = web.WorkflowTemplates(0)

            Dim choices As StringCollection = workflowTemplate.GetStatusChoices(web)
            Dim fldName As String = list.Fields.Add("Workflow Status", _
                SPFieldType.WorkflowStatus, False, True, choices)
            Dim statusUrl As String = workflowTemplate.StatusUrl

            Dim fld As SPFieldWorkflowStatus = CType(list.Fields.GetFieldByInternalName(fldName), _
                SPFieldWorkflowStatus)
            fld.Init(statusUrl, Nothing)
            fld.Update()

            Console.WriteLine("Field {0} {1} read-only.", fldName, IIf(fld.ReadOnlyField, "is", "is not"))

         End Using
      End Using
      Console.Write(vbCrLf + "Press ENTER to continue...")
      Console.ReadLine()
   End Sub
End Module
using System;
using System.Collections.Specialized;

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())
            {
               SPList list = web.Lists["Test List"];
               SPWorkflowTemplate workflowTemplate = web.WorkflowTemplates[0];

               StringCollection choices = workflowTemplate.GetStatusChoices(web);
               string fldName = list.Fields.Add("Workflow Status", 
                   SPFieldType.WorkflowStatus, false, true, choices);
               string statusUrl = workflowTemplate.StatusUrl;

               SPFieldWorkflowStatus fld = list.Fields.GetFieldByInternalName(fldName) as SPFieldWorkflowStatus;
               fld.Init(statusUrl, null);
               fld.Update();

               Console.WriteLine("Field {0} {1} read-only.", fldName, fld.ReadOnlyField ? "is" : "is not");
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}

另请参阅

引用

SPFieldWorkflowStatus 类

SPFieldWorkflowStatus 成员

Microsoft.SharePoint 命名空间

StatusUrl

StatusColumn

其他资源

Field Element (Definition)