Coding Options for Building InfoPath Forms

Coding Options for Building InfoPath Forms

hen you want to build a simple form—something with a set of fields and perhaps a table of repeating fields—it’s easy to pick up InfoPath and bang out a form in a matter of minutes, or at least within an hour. However, integrating code with your InfoPath forms can make form building a trickier proposition. Sure, VB.NET and C# are supported languages for extending InfoPath forms, but how does that support work and how are you going to be able to deploy it?

This discussion will allow you to investigate options for developing code when using InfoPath, consider the limitations, and discover ways to make intelligent, code-enabled InfoPath forms.

A Cornucopia of Coding Options
At first glance your options for developing code with InfoPath look simple. You can use either script or .NET code, namely C# or VB.NET, but in addition to language choices there are two different approaches that you can take for .NET development. You can use either Visual Studio Tools for Applications (VSTA) or Visual Studio Tools for Office (VSTO). VSTA ships with InfoPath and doesn’t require a Visual Studio license, but VSTO does. As you explore the coding options for InfoPath, consider these .NET development environments first.

The decision between VSTA and VSTO is largely akin to making a decision about what brand of car to buy. Both will get you to your destination—a smart form—but they have different characteristics in terms of their focus and approach. VSTA is a sidecar to InfoPath; it takes the InfoPath interface and binds to it to manage the code’s development.

You can use VSTA to design the form in InfoPath, and then you can write the code using the separate VSTA tool. This approach seems like a major inconvenience at first, but after a short time it becomes fairly natural. The nice part of VSTA is that if you’re working on just the form’s layout you don’t have to open VSTA. You start InfoPath and away you go.

VSTO on the other hand integrates the InfoPath designer as a part of the Visual Studio experience; therefore, you can transition between designing the form and writing code for the form without leaving the tool. If you’re approaching the form as a developer who happens to use InfoPath, then using VSTO may be the better solution. It supports source code control, even if it can be quirky.

The problem with VSTO is primarily that it’s InfoPath designer tool doesn’t reproduce InfoPath forms with 100 percent fidelity. If you can live with the quirks and have the extra time to learn more about it, VSTO is probably a better tool for long-term use.

A Tale of Two APIs
Note that the foregoing discussion doesn’t address the API model. InfoPath 2003 used a COM model that communicated through MSXML; however, InfoPath 2007 uses .NET instead. The two APIs are incompatible. You can get tips on how to convert from the 2003 model to the 2007 model by reviewing “Converting InfoPath 2003 Managed Code to the New InfoPath 2007 Object Model” (MSDN, June 2007). Just be aware that conversion is a manual process.

Perhaps the greatest changes in the object model are to the names of the root objects, such as things like the thisXDocumentobject disappearing and the change from an XML DOM-based reference model to an XML Navigator-based reference model. There are other changes, as well, such as how events are wired up. However, these events pale in comparison to the problems with learning a new set of root objects—and a completely new way of working with XML.

In regard to the change in root objects, the transitions aren’t that hard after you get used to them, but if you’ve come from an InfoPath 2003 environment you may find yourself trying to use objects that are no longer there. When you go to reuse your previous code, or code you find on the Internet, it may be temporarily frustrating to learn how to convert the code into the 2007 model.

The transition to XML Navigator objects means you’re no longer working with XMLNode objects. In truth, XML Navigator objects aren’t really all that difficult. They’re simply a pointer into the XML document, which can take a bit of getting used to because it’s a new way of working with XML. For example, instead of extracting nodes using XPath statements, you move a pointer—a bookmark—in the document with a series of movestatements or XPath queries.

The real reason why you should care about the differences between the InfoPath 2003 and InfoPath 2007 object models is because despite the fact that the InfoPath 2007 client will support both object models, InfoPath Forms Services supports only the 2007 object model.

When you’re confronted with an organization that deploys InfoPath 2003 and Microsoft Office SharePoint Server Enterprise Edition (MOSS-Enterprise), you encounter a fork in the road. You must decide to either use the 2003 model and use the InfoPath 2003 client, or use the 2007 object model and require that the form be filled out through Forms Services. This approach is complicated by the fact that InfoPath 2003 doesn’t work with MOSS content types. Therefore, if you want to create a content type for InfoPath to use, you have to essentially use InfoPath Forms Services or the InfoPath 2007 client. Obviously, this problem will fade over time as more organizations replace InfoPath 2003 by deploying InfoPath 2007. The real trick is to make the decisions up front about what limitations that you’re willing to live with and which ones you aren’t.

InfoPath supports script too, and it’s quite handy when working with task panes; however, there is a set of limitations around script that render it an unpopular first choice among many developers. For one thing, you can have only one type of code per project; that means that if you want .NET code you can’t use script. You also cannot mix JavaScript and VBScript in a script project—even though both are supported individually. Script is also not supported in Forms Services, which means it’s off limits if you plan to publish the form for use with Forms Services—and one could easily question the exclusion of script in Forms Services support.

A Matter of Trust
In today’s world it’s important, if not critical, to trust the code you’re running. With viruses, worms, and Trojans coming out of the woodwork, you can’t afford to run code today that you didn’t write, didn’t verify, or for which you don’t at least trust the source.

The publisher sets the security level of an InfoPath form, and it is confirmed by the consumer of the form template. To set the options from the category list, the designer selects Tools –> Form Options, and then on the Security and Trust pane unchecks the “Automatically determine security level (recommended)” option and manually selects the level that is appropriate for the form.

InfoPath Security
InfoPath has built-in mechanisms to limit the amount of trust that you can apply to a form. There are three security levels: restricted, domain, and full. These security levels control what the form can and cannot do.

In the restricted security level the form can’t access data outside of the form itself. In other words, all the integration with the environment (with the exception of email submission) is disabled. This level of security is not supported for Forms Server templates; they’re promoted automatically to the domain level of security. When you add an email data connection for submission, InfoPath will automatically set the form to a restrictedsecurity level.

Domain-level security allows access to the data sources in the same domain, on the local computer, and in the local intranet zone as specified in Microsoft Internet Explorer. It’s limited to utilizing built-in integration functions and some lower-level code only. Sure, forms with domain-level security can run code, but only certain methods. The article “About the Security Model for Managed Code Form Templates” (from “InfoPath Developer Reference for Managed Code” MSDN, 2007) describes in general which objects and methods are available for domain-level trust forms.

The highest level of trust, full trust, is necessary when the code in the form needs unrestricted access to the API. If you think about it, after you’re running some code, it’s possible to do nearly everything to the computer, including things that a form shouldn’t be able to do. However, fulltrust requires that the form is signed either with a code-signing certificate or installed on the computer. For a workstation this publishing happens through a standard Microsoft Windows Installer MSI file. On a Forms Server it’s published as an administrator-approved form template.

Code signing works by indicating the verified author of the form. This technique allows the user to decide whether or not to run the form. The code-signing process relies on a trust hierarchy and a secure hash. The trust hierarchy basically means that there is a set of trusted certificate authorities; these are authorities that you believe will tell you the accurate identity of a certificate holder. Microsoft provides a set of trusted authentication providers out of the box; these are organizations that Microsoft believes you should trust to provide accurate verification of the people they issue certificates to. In addition, if you’re a member of a domain and there is an enterprise certificate authority, you’ll also trust the domain’s enterprise certificate authority.

This trust hierarchy is coupled with a secure hash, which can be recalculated by every computer. The hash is calculated by the signer and then encrypted with its private key. The signer then attaches a copy of its certificate that includes its public key. The certificate itself includes the hierarchy of servers that issued the certificate. The recipient computer calculates the hash for the document and decrypts the hash in the document with the public key from the certificate. If the keys match, then the owner of the certificate—issued by a trusted source—is indeed the person who signed the code. This approach means that if you trust the person or organization that was issued the certificate, you should trust that the code came from them.

Code-signing certificates aren’t difficult to obtain, and you can purchase them from one of the trusted root certificate authorities. Or, if you’re in an organization with an active directory domain, you can issue one yourself. (You can read step-by-step instructions on how to issue a certificate in the blog post “Domain Certificate Authority Signing InfoPath 2007 Forms.”)

Approved Form Templates
Administrator-approved form templates are templates that have been published by the administrator of a Forms Services computer. The administrator of the server has specifically decided these forms are appropriate for users of the Forms Services server. Because there is a trusted person—namely, the administrator specifically approving form templates published to the Forms Services server—using InfoPath form templates with attached code doesn’t require being signed. However, this practice is a good idea given that the administrator knows who the form came from and that he or she is authorized to ask for the deployment of the form.

The process for publishing an administrative form isn’t particularly difficult; however, these forms do require access to central administration to complete—access that only a handful of users will have. After they are published, these administrator-approved form templates can be activated in any site collection on any web application in the farm.

Deciding how to add code to your InfoPath form (or for that matter whether it’s right to put code in the InfoPath form) isn’t as straightforward as it might seem at first. The simple options of script or .NET code rapidly branch into an array of options that leaves no stone unturned. Whether you choose VSTA or VSTO, the 2003 Object Model, or the 2007 Object Model, you’ll at least know the basics of what your decision means both in terms of what you can and cannot do.

Additional Resources

devx-admin

devx-admin

Share the Post:
Software Development

Top Software Development Companies

Looking for the best in software development? Our list of Top Software Development Companies is your gateway to finding the right tech partner. Dive in

India Web Development

Top Web Development Companies in India

In the digital race, the right web development partner is your winning edge. Dive into our curated list of top web development companies in India,

USA Web Development

Top Web Development Companies in USA

Looking for the best web development companies in the USA? We’ve got you covered! Check out our top 10 picks to find the right partner

Clean Energy Adoption

Inside Michigan’s Clean Energy Revolution

Democratic state legislators in Michigan continue to discuss and debate clean energy legislation in the hopes of establishing a comprehensive clean energy strategy for the

Chips Act Revolution

European Chips Act: What is it?

In response to the intensifying worldwide technology competition, Europe has unveiled the long-awaited European Chips Act. This daring legislative proposal aims to fortify Europe’s semiconductor

Revolutionized Low-Code

You Should Use Low-Code Platforms for Apps

As the demand for rapid software development increases, low-code platforms have emerged as a popular choice among developers for their ability to build applications with

Software Development

Top Software Development Companies

Looking for the best in software development? Our list of Top Software Development Companies is your gateway to finding the right tech partner. Dive in and explore the leaders in

India Web Development

Top Web Development Companies in India

In the digital race, the right web development partner is your winning edge. Dive into our curated list of top web development companies in India, and kickstart your journey to

USA Web Development

Top Web Development Companies in USA

Looking for the best web development companies in the USA? We’ve got you covered! Check out our top 10 picks to find the right partner for your online project. Your

Clean Energy Adoption

Inside Michigan’s Clean Energy Revolution

Democratic state legislators in Michigan continue to discuss and debate clean energy legislation in the hopes of establishing a comprehensive clean energy strategy for the state. A Senate committee meeting

Chips Act Revolution

European Chips Act: What is it?

In response to the intensifying worldwide technology competition, Europe has unveiled the long-awaited European Chips Act. This daring legislative proposal aims to fortify Europe’s semiconductor supply chain and enhance its

Revolutionized Low-Code

You Should Use Low-Code Platforms for Apps

As the demand for rapid software development increases, low-code platforms have emerged as a popular choice among developers for their ability to build applications with minimal coding. These platforms not

Cybersecurity Strategy

Five Powerful Strategies to Bolster Your Cybersecurity

In today’s increasingly digital landscape, businesses of all sizes must prioritize cyber security measures to defend against potential dangers. Cyber security professionals suggest five simple technological strategies to help companies

Global Layoffs

Tech Layoffs Are Getting Worse Globally

Since the start of 2023, the global technology sector has experienced a significant rise in layoffs, with over 236,000 workers being let go by 1,019 tech firms, as per data

Huawei Electric Dazzle

Huawei Dazzles with Electric Vehicles and Wireless Earbuds

During a prominent unveiling event, Huawei, the Chinese telecommunications powerhouse, kept quiet about its enigmatic new 5G phone and alleged cutting-edge chip development. Instead, Huawei astounded the audience by presenting

Cybersecurity Banking Revolution

Digital Banking Needs Cybersecurity

The banking, financial, and insurance (BFSI) sectors are pioneers in digital transformation, using web applications and application programming interfaces (APIs) to provide seamless services to customers around the world. Rising

FinTech Leadership

Terry Clune’s Fintech Empire

Over the past 30 years, Terry Clune has built a remarkable business empire, with CluneTech at the helm. The CEO and Founder has successfully created eight fintech firms, attracting renowned

The Role Of AI Within A Web Design Agency?

In the digital age, the role of Artificial Intelligence (AI) in web design is rapidly evolving, transitioning from a futuristic concept to practical tools used in design, coding, content writing

Generative AI Revolution

Is Generative AI the Next Internet?

The increasing demand for Generative AI models has led to a surge in its adoption across diverse sectors, with healthcare, automotive, and financial services being among the top beneficiaries. These

Microsoft Laptop

The New Surface Laptop Studio 2 Is Nuts

The Surface Laptop Studio 2 is a dynamic and robust all-in-one laptop designed for creators and professionals alike. It features a 14.4″ touchscreen and a cutting-edge design that is over

5G Innovations

GPU-Accelerated 5G in Japan

NTT DOCOMO, a global telecommunications giant, is set to break new ground in the industry as it prepares to launch a GPU-accelerated 5G network in Japan. This innovative approach will

AI Ethics

AI Journalism: Balancing Integrity and Innovation

An op-ed, produced using Microsoft’s Bing Chat AI software, recently appeared in the St. Louis Post-Dispatch, discussing the potential concerns surrounding the employment of artificial intelligence (AI) in journalism. These

Savings Extravaganza

Big Deal Days Extravaganza

The highly awaited Big Deal Days event for October 2023 is nearly here, scheduled for the 10th and 11th. Similar to the previous year, this autumn sale has already created

Cisco Splunk Deal

Cisco Splunk Deal Sparks Tech Acquisition Frenzy

Cisco’s recent massive purchase of Splunk, an AI-powered cybersecurity firm, for $28 billion signals a potential boost in tech deals after a year of subdued mergers and acquisitions in the

Iran Drone Expansion

Iran’s Jet-Propelled Drone Reshapes Power Balance

Iran has recently unveiled a jet-propelled variant of its Shahed series drone, marking a significant advancement in the nation’s drone technology. The new drone is poised to reshape the regional

Solar Geoengineering

Did the Overshoot Commission Shoot Down Geoengineering?

The Overshoot Commission has recently released a comprehensive report that discusses the controversial topic of Solar Geoengineering, also known as Solar Radiation Modification (SRM). The Commission’s primary objective is to

Remote Learning

Revolutionizing Remote Learning for Success

School districts are preparing to reveal a substantial technological upgrade designed to significantly improve remote learning experiences for both educators and students amid the ongoing pandemic. This major investment, which

Revolutionary SABERS Transforming

SABERS Batteries Transforming Industries

Scientists John Connell and Yi Lin from NASA’s Solid-state Architecture Batteries for Enhanced Rechargeability and Safety (SABERS) project are working on experimental solid-state battery packs that could dramatically change the

Build a Website

How Much Does It Cost to Build a Website?

Are you wondering how much it costs to build a website? The approximated cost is based on several factors, including which add-ons and platforms you choose. For example, a self-hosted

Battery Investments

Battery Startups Attract Billion-Dollar Investments

In recent times, battery startups have experienced a significant boost in investments, with three businesses obtaining over $1 billion in funding within the last month. French company Verkor amassed $2.1