Share via


SPFieldWorkflowStatus.Init method

Initializes the SPFieldWorkflowStatus object.

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

Syntax

'Declaration
Public Sub Init ( _
    strUrl As String, _
    strShowField As String _
)
'Usage
Dim instance As SPFieldWorkflowStatus
Dim strUrl As String
Dim strShowField As String

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

Parameters

  • strUrl
    Type: System.String

    The URL of a custom workflow status page. The default is _layouts/WrkStat.aspx.

  • strShowField
    Type: System.String

    The name of the field to display. The default is Status1.

Remarks

This method sets the WorkflowStatusURL attribute and the ShowField attribute of the field element definition, and sets the ReadOnlyField property of the field to true.

Examples

The following example is a console application that adds a WorkflowStatus field to the list named Test List and initializes the field.

The application requires that the Web site has a list named "Test List" and at least one workflow template.

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();
      }
   }
}

See also

Reference

SPFieldWorkflowStatus class

SPFieldWorkflowStatus members

Microsoft.SharePoint namespace

StatusUrl

StatusColumn

Other resources

Field Element (List)