Article ID: 555963 - View products that this article applies to.
Learn how to access custom configuration settings that are stored in Windows SharePoint Services web application configuration files from InfoPath browser-enabled form templates.
This article discusses how to access custom configuration settings that are stored in web configuration files from InfoPath browser-enabled form templates. It assumes that you are familiar with configuration files, the logical architecture of Windows SharePoint Services 3.0 (WSS), InfoPath Forms Services, and writing .NET code for InfoPath form templates.
InfoPath browser-enabled form templates are InfoPath form templates that have been designed to be compatible with and run in both the InfoPath client application and on a server running InfoPath Forms Services. InfoPath forms that are based on such form templates can be opened in and filled out through a web browser such as Internet Explorer. These InfoPath forms run within the context of a Windows SharePoint Services 3.0 (WSS) site or site collection. Each WSS site or site collection belongs to an WSS web application and each WSS web application uses a web configuration file. Therefore, an InfoPath form that runs in the context of an WSS site or site collection has access to settings that are stored in the web configuration file of the WSS web application of that site or site collection.
Configuration files are XML files that can be changed as needed and allow for flexible configuration of applications, either desktop or web. WSS web applications are physically stored in folders under the C:\Inetpub\wwwroot\wss\VirtualDirectories directory. Each web application has its own folder. The configuration (web.config) file for a web application is located in the root folder for the web application. You can add custom settings to this web configuration file, which InfoPath browser-enabled form templates can access and use.
Configuration settings can be programmatically accessed from an InfoPath form template just like from any other .NET application by using classes and methods defined in the System.Configuration namespace. First you must reference the System.Configuration assembly in your InfoPath project in Visual Studio or Visual Studio Tools for Applications (VSTA) and then you can write code to retrieve the values of custom configuration settings from the configuration file as shown in the following code:
where the appSettings section in the configuration file has an add element that defines a custom application setting named AppName with a value of InfoPath2007 as follows:
Once you have retrieved the value of the custom application setting from the configuration file, you can use it in your InfoPath form template to dynamically configure default values of list boxes, show or hide sections based on conditional formatting, pre-fill fields with data, etc.
Typically, you must publish an InfoPath browser-compatible form template to a server running InfoPath Forms Services and browser-enable it before you can debug it in Visual Studio. And since you must write .NET code to access configuration settings, you cannot publish the InfoPath form template directly to the server; an administrator must approve and upload it to the server. However, you can avoid having to publish an InfoPath form template to a server running InfoPath Forms Services for the sole purpose of testing and debugging code that accesses configuration settings.
Whenever you preview an InfoPath form, the InfoPath client application, INFOPATH.EXE, is executed to be able to open and display the InfoPath form in Preview mode. This applies to both Visual Studio and Visual Studio Tools for Applications (VSTA). So if you want an InfoPath form template to access configuration settings while you are debugging it, you must create a local application configuration file that INFOPATH.EXE can access and use.
Perform the following steps to create an application configuration file for INFOPATH.EXE:
Now you can set breakpoints throughout your code and run and debug the code that accesses configuration settings.
Listing 1. Sample contents of infopath.exe.config file.
InfoPath forms that are based on InfoPath browser-enabled form templates can access web configuration settings of the WSS site or site collection they are opened in. You can use classes and methods defined in the System.Configuration namespace to write code that accesses these configuration settings from within InfoPath form templates. You can create a temporary application configuration file for the InfoPath client application to use, so that you can test and debug configuration code without first having to publish an InfoPath browser-compatible form template to a server running InfoPath Forms Services and browser-enable it.
Article ID: 555963 - Last Review: September 26, 2007 - Revision: 1.0
COMMUNITY SOLUTIONS CONTENT DISCLAIMER
MICROSOFT CORPORATION AND/OR ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY, RELIABILITY, OR ACCURACY OF THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN. ALL SUCH INFORMATION AND RELATED GRAPHICS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT AND/OR ITS RESPECTIVE SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THIS INFORMATION AND RELATED GRAPHICS, INCLUDING ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, WORKMANLIKE EFFORT, TITLE AND NON-INFRINGEMENT. YOU SPECIFICALLY AGREE THAT IN NO EVENT SHALL MICROSOFT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, PUNITIVE, INCIDENTAL, SPECIAL, CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF USE, DATA OR PROFITS, ARISING OUT OF OR IN ANY WAY CONNECTED WITH THE USE OF OR INABILITY TO USE THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN, WHETHER BASED ON CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY OR OTHERWISE, EVEN IF MICROSOFT OR ANY OF ITS SUPPLIERS HAS BEEN ADVISED OF THE POSSIBILITY OF DAMAGES.
Contact us for more help