Share via


XmlForm.FormState Property (Microsoft.Office.InfoPath)

Gets a reference to a property bag of type System.Collections.IDictionary that browser-enabled forms can use to maintain state information across sessions on the server.

Namespace: Microsoft.Office.InfoPath
Assembly: Microsoft.Office.InfoPath (in microsoft.office.infopath.dll)

Syntax

'Declaration
Public MustOverride ReadOnly Property FormState As IDictionary
'Usage
Dim instance As XmlForm
Dim value As IDictionary

value = instance.FormState
public abstract IDictionary FormState { get; }

Property Value

An IDictionary that contains any user-defined state variables that were defined in the declarations section of the form code.

Remarks

This member can be accessed without restrictions.

This type or member can be accessed from code running in forms opened in Microsoft Office InfoPath 2007 or in a Web browser.

Example

The following example shows a design pattern for creating a state variable in the declarations section of the FormCode class (before the InternalStartup method) that functions as a counter. This example checks whether the _Counter variable is null before returning the value to avoid errors where the FormState array was not initialized.

private int _Counter
{
   get
   {
      if(FormState["_Counter"] != null)
      {
         return (int) FormState["_Counter"];
      }
      else
      {
         return 0;
      }
   }
   set
   {
      FormState["_Counter"] = value;
   }
}
Private Property _Counter As Integer
   Get
      If(FormState("_Counter") != null) Then
         _Counter = DirectCast(FormState("_Counter"), Integer)
      Else
         _Counter = 0
      End If
   End Get
   Set
      FormState("_Counter") = value
   End Set
End Property

See Also

Reference

XmlForm Class
XmlForm Members
Microsoft.Office.InfoPath Namespace