That's a mouthful, isn't it?

First of all, you know what I mean by managed code business logic in InfoPath, right?

Also, you know what a Fully Trusted InfoPath Form is, right? If not, here's a refresher.

Let's say you're a form developer, and you've been tasked with developing a form which requires managed code business logic AND calls into InfoPath Level 3 OM (like XDocument.UI.ShowModalDialog).

So, you start Visual Studio.NET 2003, choose to create a new InfoPath Project (you did install the InfoPath 2003 Toolkit for Visual Studio.NET, right?) , and choose Visual C# Project. Finish the wizard, and you've got yourself a managed code InfoPath form. To debug the form, all you need to do is hit F5, and the debugger will launch. 

Now, let's make the form Fully Trusted. You have 3 options:

  1. Register the Form (via a script/msi created by using RegForm Tool in the SDK)
  2. Register the Form (via a handwritten script which calls Level 3 OM method Application.RegisterSolution)
  3. Sign the Form (you can create a test code signing certificate using the InfoPath Designer)

One other thing to note: When working with InfoPath VS Projects, the form is in “extracted” format, meaning all the xsd, xsl, xml, and other files are sitting in a folder, as opposed to all wrapped up in an .xsn file (which is the default way to deploy forms). When you are ready to deploy your form to your users, use the Publishing Wizard to generate an .xsn file for your form.

Back to the matter of making the form Fully Trusted.

RegForm: Since you're working with extracted form files, you won't be able to use the RegForm tool in the SDK. If you MUST use RegForm, here are the steps:

  1. Publish the form to generate an .xsn file
  2. Run RegForm on the .xsn file to generate a .js file to register the form
  3. Run the .js file to register the form.
  4. Start the form, then attach VS to the InfoPath process to debug.

But wait, there's more... After you've made a change to your code, you'll need to unregister the form, delete js files, republish the form, etc. It all gets very messy.

Signing Forms: You also won't be able to use the signing method to make your form fully trusted, for the same reason. You can't sign extracted form files. You'll have to publish the form, sign the published .xsn, and then attach VS to the process in order to debug. You'll need to do this step every time you make a change to your code. Again, this is less than ideal.

RegisterSolution OM: The only other method remaining is to register the form without using RegForm. You can simply write your own .js file which calls RegisterSolution(), and register the manifest.xsf in your project folder.

1. Open the manifest.xsf and remove the publishURL. (required to make the form Fully Trusted)
2. Write a script file which calls into InfoPath External Automation to call RegisterSolution on the manifest.xsf file.

'Sample courtesy of Jeff Webb
'http://www.mcse.ms/archive180-2004-4-605806.html
set ip = CreateObject("InfoPath.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
pth = fso.GetFolder(".").path
ip.registersolution pth & "\manifest.xsf"
set ip = nothing
set fso = nothing

3. Run the script file.

Now you should be able to simply hit F5 to debug your form, and it should be able to successfully call any InfoPath Level 3 OM Methods (XDocument.UI.ShowModalDialog, etc) without a security exception. Changes to your code are also automatically updated without having to republish. Sweetness.

Note: When you're ready to deploy your form to your users, you should still publish your form, and utilize RegForm or code signing certificates to make your forms fully trusted. This posting is simply talking about how to debug your form without losing your mind.