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
Anonymous
May 30, 2012
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.Anonymous
May 30, 2012
See the MSDN article, msdn.microsoft.com/.../bb251012(v=office.12).aspx for how to get the context ID. With the ID, the SelectText method works from C# in VSTO 4.