Table of Contents
List of Figures xxi
List of Tables xlvii
Foreword li
Preface lv
About the Authors lxv
PART I: Designing Forms 1
Chapter 1: Introduction to InfoPath 2007 3
What Is InfoPath? 3
InfoPath 2003 7
InfoPath 2003 Service Pack 1 12
InfoPath 2007 17
What's Next? 24
Chapter 2: Basics of InfoPath Form Design 25
Getting Started 25
What Is a Form Template Anyway? 26
Design a Form Template Dialog 27
Creating a New Blank Form Template 30
Designing the Layout of Your Form 34
Using Controls 41
Creating Multiple Views 73
Advanced Formatting 76
What's Next? 83
Chapter 3: Working with Data 85
Getting Started 85
Data Binding 86
Data Source Field and Group Properties 95
Manually Editing the Data Source 110
Advanced Data Binding 137
Editing Default Template Data 151
What's Next? 154
Chapter 4: Advanced Controls and Customization 155
Getting Started 155
Advanced Controls 156
Control Properties 174
Advanced Customizations 204
What's Next? 213
Chapter 5: Adding Logic without Code 215
Getting Started 215
Conditional Formatting 215
Data Validation 222
Rules 229
Logic Inspector 235
What's Next? 240
Chapter 6: Retrieving Data from External Sources 241
Getting Started 241
Data Connections 242
XML Files 247
Databases 256
Web Services 273
SharePoint Libraries and Lists292
What's Next? 296
Chapter 7: Extended Features of Data Connections 297
Getting Started 297
Extended Features of Web Services 298
Secondary Data Source Binding 307
Offline Mode Query Support 312
List Box Controls Connected to Secondary Data Sources 316
What's Next? 325
Chapter 8: Submitting Form Data 327
Getting Started 327
Why Submit? 328
Submitting Forms 334
ADO.NET DataSetSubmit 369
Submit Options 392
What's Next? 395
Chapter 9: Saving and Publishing 397
Getting Started 397
Saving and Publishing a Form Template with InfoPath 398
Saving Templates as Extracted Source Files 421
Previewing Form Templates 424
What's Next? 430
Chapter 10: Building Reusable Components 431
Getting Started 431
Designing a New Template Part 432
Using a Template Part 438
Updating Template Parts 447
Customizing Existing Template Parts 452
What's Next? 454
Chapter 11: Security and Deployment 455
Getting Started 455
Introduction to InfoPath Security 456
InfoPath Security Levels 458
Trust and Designer Lockdown 499
Digital Signatures 507
Information Rights Management 538
What's Next? 552
Chapter 12: Creating Reports 553
Getting Started 553
Merging Forms 554
Printing 586
Exporting Forms 605
What's Next? 612
Chapter 13: Workflow 613
Getting Started 613
User Roles 614
Workflow with Microsoft Office SharePoint
Server 2007 634
Workflow with InfoPath E-Mail Forms 643
What's Next? 663
Chapter 14: Introduction to Forms Services 665
Getting Started 665
What Is InfoPath in the Browser? 666
Installing and Configuring Forms Services 671
Publishing a Form Template to Forms Services 678 Getting Familiar with Browser Forms 682
Designing a Browser-Enabled Form Template 690
Getting Familiar with the Browser Form Experience 701 SharePoint Integration 705
Data Connections 710
Filling Out Browser Forms 714
Mobile Support: Smart Phone and PDA 720
What's Next? 726
Part II: Advanced Form Design 727
Chapter 15: Writing Code in InfoPath 729
Getting Started 729
Writing Code Behind a Form 730
The InfoPath Object Model 741
Programming InfoPath...in Action! 790
What's Next? 832
Chapter 16: Visual Studio Tools for Microsoft Office InfoPath 2007 833
Getting Started 833
What Is VSTO? 834
Bringing InfoPath into Visual Studio 835
Installing VSTO 836
Designing a Form Template with VSTO 836
Previewing a Form in VSTO 863
What's Next? 864
Chapter 17: Advanced Forms Services 865
Getting Started 865
Controls and Browser Optimizations 867
Form Code 875
SharePoint Integration 885
Data Connections 929
Performance Tips and Best Design Practices 950
What's Next? 963
Chapter 18: Hosting InfoPath 965
Getting Started 965
Hosting Scenarios 966
Document Information Panel 966
Creating an InfoPath Host Application 977
Hosting the InfoPath Form Control in a Web Browser 1011
What's Next? 1036
Chapter 19: Building Custom Controls Using ActiveX Technologies 1037
Getting Started 1037
Installing and Using ActiveX Controls 1038
Building Custom Controls for InfoPath Using ActiveX 1049
What's Next? 1072
Chapter 20: Add-ins 1073
Getting Started 1073
Introduction to COM Add-ins 1074
Building a COM Add-in for InfoPath 1076
Custom Task Panes 1093
Writing Add-ins and Custom Task Panes Using VSTO 2005 SE 1105
Managing InfoPath Add-ins 1111
What's Next? 1114
Chapter 21: Importers and Exporters 1115
Getting Started 1115
Built-in Form Importers 1116
Creating Your Own Form Importers and Exporters 1128
Importing Form Data 1142
What's Next? 1148
Appendix: Further Reading 1149
Index 1157
Forewords & Introductions
It Just Makes Sense
Over the past ten years, Extensible Markup Language (XML) has become more widely used than ever before as a means of transferring data between applications and even between organizations. XML provides a standard protocol with which these applications and organizations can communicate. Using XML Schema, a company can define a standard structure for its data that can then be used across multiple departments and organizations. This structured data enables developers to easily create applications that can communicate with each other without much effort.
In addition, most organizations use forms in one way or another, whether to enter a purchase request, submit expense report information, or track weekly status. If you look at a typical form, you will notice that the form itself is structured unlike a typical freeform document created in an application such as Microsoft Office Word 2007. In these freeform documents you can type anything you like in any way that you choose. Although a form may contain sections that allow you to enter freeform text such as comments, most of your typical forms are highly structured. Fields in the form usually require you to enter specific types of data such as sales numbers or costs. Since XML defines a structured data format (which can contain some unstructured elements) and forms are highly structured with bits of freeform data, it makes sense to tie together forms and XML data. Once a user has filled out a form that is connected to XML data, the data can easily be incorporated into back-end processes that understand the structure of the XML data for that form. So, this fits one of the main purposes of XML--tyingtogether multiple processes using a standard protocol.
Since building forms based on XML just makes sense, many software developers want to create forms-based applications to collect data and store it as XML. However, until a few years ago, this was a tedious and time-consuming process. Developers had to use tools such as Microsoft Visual C++, C#, or Visual Basic .NET and write sometimes a tremendous amount of code to create a forms application. Often, forms applications share similar functionality, such as spell checking, calculations, and data validation. In order to share this functionality across multiple forms applications, software developers needed to create code libraries in order to reuse their code. This worked fine when sharing the code within the same department or company. However, developers across multiple companies were likely going to duplicate the same work unless, of course, companies purchased these libraries from a third-party vendor.
Developing forms applications in this way is not something that typical information workers can do. Usually this type of coding is reserved for advanced software developers. Another disadvantage of this approach is that different forms applications usually have different user interfaces. Each time a user fills out a form, he or she may need to learn a different set of commands and menu items. This learning curve costs the company time and money.
About five years ago, Microsoft recognized the need for a common tool to build forms based on XML technologies. Existing XML-based tools required a thorough understanding of XML, so most information workers had trouble understanding how to use them. Also, most information workers do not know how to write code and, therefore, could not easily use development tools such as Microsoft Visual Studio. Therefore, it just made sense to create a tool that developers and information workers could use to create forms based on XML and that users could use to fill out those forms. That tool is InfoPath. (In Chapter 1, we'll tell you exactly what InfoPath is all about and introduce you to the extensive feature set included in this application.)
Looking at the wealth of features included in InfoPath, especially those added in InfoPath 2007, it also just made sense to create this book. This book is titled Designing Forms for Microsoft Office InfoPath and Forms Services 2007 for a reason. It's all about designing forms using InfoPath 2007, as we're sure you have figured out by now. This book will teach you everything you need to know about creating forms using InfoPath 2007 and probably a few things you never thought you needed to know.
Who Should Read This Book
Whether you are an information worker who has created only a few forms in Word or a software developer who is familiar with more advanced coding concepts, if your intention is to learn how to design InfoPath forms, this book is for you. This book will talk about not only the basics of designing forms but also such advanced concepts as writing managed code for InfoPath. As long as you have an understanding of basic form concepts and a desire to learn, you are in the right place. If you want to learn everything you can about InfoPath 2007, you have found the right book.
How This Book Is Organized
This book contains two parts. Part I is all about designing forms in InfoPath. No prior coding experience is required to understand the concepts, so both information workers and developers can use Part I to learn the basics of InfoPath form design. Many chapters build on previous chapters and become slightly more advanced as you progress. For example, in Chapter 4 we discuss advanced controls and customization, but by Chapter 6 we show how to pull external data, such as from a Web service, into your forms. By the time you finish reading Part I, you should know everything you need to know to design an InfoPath form for the InfoPath client application or for the browser without having to write any code.
Part II is about advanced form design. In this part of the book we talk about using more advanced form design techniques, including how to write code for InfoPath. These chapters are geared mainly toward software developers who have some basic coding experience. However, if you are an information worker and you have completed Part I of this book, the second part may interest you as well. In Part II, we talk about such topics as the InfoPath object model (Chapter 15), advanced topics regarding InfoPath Forms Services (Chapter 17), and ways to host InfoPath (Chapter 18).
Conventions Used in This Book
We use a few typographical conventions throughout this book. Bold text indicates key topics or terms. The names of features shown in the user interface, such as menu items, appear in italic text.
Information that pertains to InfoPath Forms Services is clearly displayed as features in the text. These tips will let you know when certain InfoPath features work differently in browser forms or don't work at all.
Samples
Almost every chapter in this book has one or more samples, which you can download from the Addison-Wesley Web site for this book. Sometimes the samples are InfoPath form templates (.xsn) files, which is the case throughout Part I. In order to use these form templates, you first need to open them in InfoPath design mode and resave them to a local folder. (This will make more sense after you start reading Part I.) Trying to open the form template in order to fill it out without first saving it will result in an error. Some samples include form (.xml) files in addition to form templates. To open the forms, first open InfoPath, and then open the XML file using the standard
Open dialog (i.e., click on the
On My Computer link from the
Getting Started dialog.) The first time you open one of the sample forms, the dialog shown in Figure P.1 will be displayed. This dialog allows you to choose the form template associated with the form you are trying to open. The text of the chapter indicates the correct form template to use. After you choose the form template, click the checkbox
Always use this form template for this file. After the form is opened, immediately save it. This will prevent you from having to choose the form template each time you open the form. Some sample form templates define one or more data connections. For these samples to work properly, the external data source must exist. To see if a form template depends on a data connection, go to the
Data Connections menu item under the
Tools menu while in design mode. Since there are many types of data connections, we'll describe how to set up each one to successfully preview the form.
- XML document: If the XML (.xml) file exists within the form template (under the Resource Files menu item on the Tools menu), there is nothing you need to do. If the XML file is external to the form template, you will need to click the Modify button on the Data Connections dialog to point to your copy of the XML file. You can find the file within the samples for a given chapter.
- Database: A database connection depends on a SQL Server or Access database. If the sample uses a SQL Server database, you must have SQL Server installed and have administrative rights to the SQL Server instance. For an Access database, the chapter will include an Access database (.mdb) file. For either case, click the Modify button on the Data Connections dialog to update the data connection to point to your database to restore the connection.
- Web service: To use a Web service, you must have Internet Information Services (IIS) 6.0 or higher installed on your computer. The ASP.NET 2.0 ISAPI Web extension must be enabled, and ASP.NET should be configured to render .aspx pages. Copy the Web service code from the sample and paste it into a new ASP.NET Web service project in Visual Studio 2005. If you don't have Visual Studio, you can still create the Web service by creating a text file with extension .aspx within an IIS virtual directory. Check to see if the Web service code requires read or write access to specific directories; you can grant access to those directories or simply update the code to use directories of your choice. Before using the Web service with InfoPath, try navigating to the Web service by using a Web browser on the local machine. Once the Web service works outside of InfoPath, you can click the Modify button in the Data Connections dialog to change the Web service connection from the sample
- SharePoint library or list: The prerequisite to using samples with a SharePoint library or list connection is a Microsoft Office SharePoint server. If you have a SharePoint server, ensure you have at least reader rights if the connection is only reading data. Likewise, if the sample form template submits to a SharePoint library, you must have contributor or higher privilege. Ensure the library or list upon which the form template depends actually exists on the server. To use your library or list, edit the connection to point to your server and select the appropriate library or list.
In Part II of this book, most of the samples include code. Those samples that require you to perform special actions (or actions in a specific order) to build the samples include ReadMe.txt files that explain what you need to do.
For sample form templates that include form code, you must do the following. First, find the sample form template (.xsn) and archive (.zip) files with the same name. Extract the archive to a location on your computer by right-clicking on the .zip file and selecting Extract All. Next, open the form template in design mode as you would for samples without form code. Select the Microsoft Visual Studio Tools for Applications (VSTA) menu item under Tools and then Programming. If InfoPath cannot find the VSTA project, the dialog shown in Figure P.2 appears. Click the Browse button to navigate to the Visual C# Project (.csproj) file within the extracted folder. Once the Microsoft Visual Studio Tools for Applications window appears, hit F5 to fill out the form while previewing it. The debugger will be automatically attached, so any breakpoints or unhandled exceptions halt form execution.
Some samples in Part II require references to the interop assemblies for InfoPath. In order to set a reference to the correct interop assemblies, open the Add Reference dialog in Visual Studio and browse to the install location for Microsoft Office 2007. (This is usually C:\Program Files\Microsoft Office\Office12.) Then, locate the ipeditor.dll file and select it. This will include the Microsoft.Office.Interop.InfoPath interop assembly that you need as well as a few assemblies that aren't needed. In order to be able to install the samples, you will need to remove the references to the ADODB, MSHTML, and MSXML2 assemblies. Some samples use the Microsoft. Office.Interop.InfoPath.Xml assembly. You can also locate this assembly in the install location for Office 2007.
Some code snippets that you see within chapters may differ from the code in the sample. Due to space constraints, brevity in code may have resulted in reformatting or removal of comments or error-handling code that are not required to understand the sample. Regardless, the functionality of the code itself remains unaffected. Note that the code included with the sample form templates is not considered production quality. The code samples, not to mention the form templates themselves, have not been subjected to the rigorous testing you would expect from a company such as Microsoft.
Feedback
After you read this book, we would love to hear what you think about it--both positive and negative. This will help us improve future revisions. Also, feel free to send us any questions you may have. We would be happy to help. To contact us, simply send us an e-mail at . If you have a question, either Scott or Hagen will reply as quickly as possible. We hope that you enjoy the book and that it makes the process of designing InfoPath form templates much easier.