Calling SelectText (and other InfoPath methods with optional parameters) in C# or VB.NET

In the introduction to SP1, InfoPath added C# support. One issue that some people may run into is that certain OM calls have optional parameters. One such method is the SelectText() method in the View object. The context ID is optional and it not always easily found. In JavaScript of VBscript, the optional parameter would just be omitted and everything would work. In managed code (C# and VB.NET), you cannot omit optional parameters. To get around this, managed code has System.Reflection.Missing.Value which can be used in place of the optional parameter. This will achieve the same result as omitting optional parameters.

Comments (2)

  1. herb says:

    This doesn't work with VSTO 4, the SelectText() method now takes the node and a string.  The string is the context ID but since its no longer an object, you can't use Type.Missing.

  2. herb says:

    See the MSDN article,…/bb251012(v=office.12).aspx for how to get the context ID.  With the ID, the SelectText method works from C# in VSTO 4.

Skip to main content