Tải bản đầy đủ (.pdf) (1,293 trang)

designing forms for microsoft office infopath and forms services 2007

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (24.77 MB, 1,293 trang )

www.it-ebooks.info
Designing Forms for
Microsoft Office InfoPath
and Forms Services 2007
www.it-ebooks.info
www.it-ebooks.info
Scott Roberts
Hagen Green
Designing Forms
for Microsoft Office
InfoPath and
Forms Services 2007
Upper Saddle River, NJ • Boston • Indianapolis • San Francisco
New York • Toronto • Montreal • London • Munich • Paris
Madrid • Capetown • Sydney • Tokyo • Singapore • Mexico City
www.it-ebooks.info
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks.
Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations
have been printed with initial capital letters or in all capitals.
The .NET logo is either a registered trademark or trademark of Microsoft Corporation in the United States
and/or other countries and is used under license from Microsoft.
The authors and publisher have taken care in the preparation of this book, but make no expressed or implied war-
ranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or con-
sequential damages in connection with or arising out of the use of the information or programs contained herein.
The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special
sales, which may include electronic versions and/or custom covers and content particular to your business,
training goals, marketing focus, and branding interests. For more information, please contact:
U.S. Corporate and Government Sales
(800) 382-3419

For sales outside the United States please contact:


International Sales

Visit us on the Web: www.awprofessional.com
Library of Congress Cataloging-in-Publication Data
Roberts, Scott, 1969–
Designing forms for Microsoft Office Infopath and forms services 2007 / Scott Roberts, Hagen Green.
p. cm.
Includes bibliographical references and index.
ISBN 0-321-41059-9 (pbk. : alk. paper)
1. Microsoft InfoPath. 2. Business—Forms—Computer programs. I. Green, Hagen. II. Title.
HF5371.R63 2007
651'.29028553—dc22
2006036478
Copyright © 2007 Pearson Education, Inc.
All rights reserved. Printed in the United States of America. This publication is protected by copyright, and per-
mission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For
information regarding permissions, write to:
Pearson Education, Inc.
Rights and Contracts Department
75 Arlington Street, Suite 300
Boston, MA 02116
Fax: (617) 848-7047
ISBN 0-321-41059-9
Text printed in the United States on recycled paper at Courier in Stoughton, Massachusetts.
First printing, February 2007
www.it-ebooks.info
To my wife, Andrea, and my two sons, Sean and Bradley.
It is due to your constant love and support that I was able to
complete this project. Thank you for always being there for me

no matter what project I undertake. I love you all a million times
more than you could ever possibly know.
—Scott
To Jaime, my love and my life, for putting up with my two jobs
and helping me stay strong through the end. And to my parents,
Stuart and Christine, for their perseverance in love and for being
the best parents anyone could ask for.
—Hagen
www.it-ebooks.info
This page intentionally left blank
www.it-ebooks.info
Contents at a Glance
List of Figures xxi
List of Tables xlvii
Foreword li
Preface lv
About the Authors lxv
PART I Designing Forms 1
1 Introduction to InfoPath 2007 3
2 Basics of InfoPath Form Design 25
3 Working with Data 85
4 Advanced Controls and Customization 155
5 Adding Logic without Code 215
6 Retrieving Data from External Sources 241
7 Extended Features of Data Connections 297
8 Submitting Form Data 327
9 Saving and Publishing 397
10 Building Reusable Components 431
11 Security and Deployment 455
12 Creating Reports 553

13 Workflow 613
14 Introduction to Forms Services 665
vii
www.it-ebooks.info
PART II Advanced Form Design 727
15 Writing Code in InfoPath 729
16 Visual Studio Tools for Microsoft Office InfoPath 2007 833
17 Advanced Forms Services 865
18 Hosting InfoPath 965
19 Building Custom Controls Using ActiveX Technologies 1037
20 Add-ins 1073
21 Importers and Exporters 1115
Appendix: Further Reading 1149
Index 1157
Contents at a Glance
viii
www.it-ebooks.info
Contents
List of Figures xxi
List of Tables xlvii
Foreword li
Preface lv
About the Authors lxv
PART I Designing Forms 1
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

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 the Layout Task Pane 34
Color Schemes 39
ix
www.it-ebooks.info
Using Controls 41
Standard Controls 43
Repeating and Optional Controls 49
File and Picture Controls 67
Creating Multiple Views 73
Advanced Formatting 76
Control Formatting 78
Format Painter 79
Formatting Multiple Controls 80
What’s Next? 83
3 Working with Data 85
Getting Started 85
Data Binding 86
Creating the Data Source Automatically 86
Understanding Data Source Details 93
Data Source Field and Group Properties 95
Name Property 95
Data Type Property 98
Cannot Be Blank Property 101
Repeating Property 102

Default Value Property 106
Data Source Details 108
Manually Editing the Data Source 110
Adding Nodes 116
Moving Nodes 119
Deleting Nodes 121
Referencing Nodes 122
Starting with Your Own Data Source 124
Advanced Data Binding 137
Understanding Data Binding 138
Design-Time Visuals 149
Editing Default Template Data 151
What’s Next? 154
Contents
x
www.it-ebooks.info
4 Advanced Controls and Customization 155
Getting Started 155
Advanced Controls 156
Hyperlink 156
Expression Box 158
Vertical Label 163
Scrolling Region and Horizontal Region 164
Choice Group, Repeating Choice Group, and Choice Section 167
Repeating Recursive Section 171
Custom Controls 173
Control Properties 174
Data Tab 176
Display Tab 182
Size Tab 189

Advanced Tab 193
Creating Master/Detail Relationships 198
Advanced Customizations 204
Editing Default Values 204
Customizing Commands 210
What’s Next? 213
5 Adding Logic without Code 215
Getting Started 215
Conditional Formatting 215
Data Validation 222
Adding Data Validation to a Form Template 223
Pattern Matching 227
Rules 229
Logic Inspector 235
What’s Next? 240
6 Retrieving Data from External Sources 241
Getting Started 241
Data Connections 242
Why Do We Need Them? 242
Contents xi
www.it-ebooks.info
Conceptually Understanding Data Connections and Data Sources 242
All Data Connections Are Not Created Equal 244
Creating a Data Connection 245
XML Files 247
Databases 256
Setting Up a Connection to a Database 257
Integrating the Database Connection into the Form Template 268
Web Services 273
What Is a Web Service? 273

Creating a Simple Web Service Using Visual Studio 2005 274
Using the Simple Web Service 279
InfoPath Web Services 280
Web Service Repository 291
SharePoint Libraries and Lists 292
What’s Next? 296
7 Extended Features of Data Connections 297
Getting Started 297
Extended Features of Web Services 298
Searching with UDDI 299
ADO.NET Web Services 300
Secondary Data Source Binding 307
Designing the Form Template 307
Filling Out the Form 310
Offline Mode Query Support 312
List Box Controls Connected to Secondary Data Sources 316
Showing Secondary Data in a List Box Control 317
Using the Main Data Source for List Box Items 321
Filtering List Box Items 323
What’s Next? 325
8 Submitting Form Data 327
Getting Started 327
Why Submit? 328
Using the “Form-Only” Model to Disable Save 329
Issues with Data Validation and Submitting Forms 331
Contents
xii
www.it-ebooks.info
Submitting Forms 334
Introduction to Submit Data Connections 334

What Submit Method Is Best for My Form Template? 335
Submitting via E-Mail 337
Submitting to a Database 341
Submitting to a Web Service 344
Including Text and Child Elements Only 358
XML Subtree, Including the Selected Element 361
Entire Form 362
Submitting Digitally Signed Form Data 365
ADO.NET DataSet Submit 369
Designing a Form Template with a Dataset 370
Filling Out the Dataset Form 375
Submitting to a SharePoint Library 377
Submitting to a Web Server via HTTP 380
Custom Submit Using Form Code 383
Custom Submit Using Rules 384
Submitting to a Hosting Environment 391
Submit Options 392
What’s Next? 395
9 Saving and Publishing 397
Getting Started 397
Saving and Publishing a Form Template with InfoPath 398
Network Locations 400
SharePoint or Forms Services 404
E-Mail 413
Installable Form Templates 417
Common Conveniences 420
Saving Templates as Extracted Source Files 421
Previewing Form Templates 424
With Sample Data 426
With User Roles 427

Domain Simulation 428
Saving Form Data 429
What’s Next? 430
Contents xiii
www.it-ebooks.info
10 Building Reusable Components 431
Getting Started 431
Designing a New Template Part 432
Template Part Design Mode 434
Using a Template Part 438
Adding a Template Part to the Controls Task Pane 438
Inserting a Template Part into a Form Template 442
Updating Template Parts 447
Updating a Form Template That Contains the
AddressBlock Template Part 449
Locating All Template Parts That Need to Be Updated 451
Customizing Existing Template Parts 452
What’s Next? 454
11 Security and Deployment 455
Getting Started 455
Introduction to InfoPath Security 456
InfoPath Security Levels 458
Designing Security into Form Templates 459
Restricted Security Level 460
Domain Security Level 467
Automatic Security Level 482
Full Trust Security Level 484
Trust and Designer Lockdown 499
Trust Center 499
Designer Lockdown 504

Digital Signatures 507
Using Digitally Signed Data in Forms 509
Allowing Only One Signature 527
Using Independent Signatures (Co-signing) 531
Setting Up Counter-Signatures 532
Digital Signatures in the XML Data and Schema 533
Information Rights Management 538
Permission on Form Templates 539
Permission on Forms 542
Contents
xiv
www.it-ebooks.info
Permission with Document Libraries 548
What’s Next? 552
12 Creating Reports 553
Getting Started 553
Merging Forms 554
Merging Forms in InfoPath 555
Design Recommendations for Merging Forms 561
Customizing Merge Behavior in Design Mode 564
Custom Merge XSL (Advanced) 580
Printing 586
Print Views 586
Headers and Footers 589
Multiple View Printing 592
Word Print Views 596
Print Views in Browser-Enabled Forms 603
Exporting Forms 605
What’s Next? 612
13 Workflow 613

Getting Started 613
User Roles 614
Creating User Roles 616
Determining a User’s Role When Filling Out a Form 620
User Roles in Action 621
Role-Based Views 631
Workflow with Microsoft Office SharePoint
Server 2007 634
Workflow with InfoPath E-Mail Forms 643
Designing and Using InfoPath E-Mail Forms 644
Creating Rules for InfoPath E-Mail Forms 648
Storing Received Forms in Outlook Folders 650
Filling Out an InfoPath E-Mail Form 652
Sorting, Grouping, and Filtering Responses 656
Merging and Exporting InfoPath E-Mail Forms 657
Customizing E-Mail Support for a Form Template 660
What’s Next? 663
Contents xv
www.it-ebooks.info
14 Introduction to Forms Services 665
Getting Started 665
What Is InfoPath in the Browser? 666
Why Use the Browser? 668
What Is Forms Services? 669
Installing and Configuring Forms Services 671
Installing Forms Services 673
Configuring Forms Services 675
Is Forms Services Installed? 677
Publishing a Form Template to Forms Services 678
Getting Familiar with Browser Forms 682

Creating a New Form 682
Toolbar 683
Controls 688
Supported Web Browsers 690
Designing a Browser-Enabled Form Template 690
Design Once 692
Design Checker 693
Browser-Enabled Forms without the Design Checker 701
Designing Browser-Enabled Template Parts 701
Getting Familiar with the Browser Form Experience 701
SharePoint Integration 705
Document Libraries 705
Site Content Type 709
Data Connections 710
Data Connection Libraries 711
Security and Data Connection Libraries 713
Filling Out Browser Forms 714
Configurations Supported by Forms Services 715
URL-Based Options 716
Mobile Support: Smart Phone and PDA 720
Mobile Compatibility 722
Filling Out a Mobile Form 725
What’s Next? 726
Contents
xvi
www.it-ebooks.info
Part II Advanced Form Design 727
15 Writing Code in InfoPath 729
Getting Started 729
Writing Code Behind a Form 730

Settings Related to Adding Code 732
Adding Code to a Form Template 737
Filling Out and Debugging a Form with Code 738
The InfoPath Object Model 741
Form Events 742
XML Data Events 744
Using
XPathNavigator Objects 777
Registering Event Handlers 780
Script and the Custom Task Pane 782
Programming InfoPath in Action! 790
The MOI Consulting Request Form 791
Filling Out the MOI Consulting Request Form 792
Designing the MOI Consulting Request Form 797
What’s Next? 832
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
Start Designing a Form Template 837
The VSTO Design Experience 843
The VSTO Feature Set 853
Missing Features in VSTO 861
Previewing a Form in VSTO 863
What’s Next? 864
Contents xvii
www.it-ebooks.info
17 Advanced Forms Services 865

Getting Started 865
Controls and Browser Optimizations 867
Postback Settings 871
The Update Button 872
Designing Accessible Forms 874
Form Code 875
Executing Form Code in the Browser 876
Circumventing Browser-Enabled Limitations 878
Detecting the Browser or the InfoPath Client 883
Form Code Compatibility with Forms Services 884
SharePoint Integration 885
Advanced Publishing 888
Managing Form Templates 904
Configuring InfoPath Forms Services 906
Configuring Shared Services and Providers 907
Filling Out a Form on a SharePoint Page 928
Data Connections 929
Data Connections Administration Settings 931
Centrally Managed Connection Library 936
Authentication Considerations 943
E-Mail Data Connections 948
Performance Tips and Best Design Practices 950
Form Template Deployment 951
Views 952
Form Code 953
Reduction of Form Postbacks 953
Data-Heavy Features 954
Data Connections 956
Form View State 956
Miscellaneous Performance Tips 957

Performance Monitoring 958
Health Monitoring 962
What’s Next? 963
Contents
xviii
www.it-ebooks.info
18 Hosting InfoPath 965
Getting Started 965
Hosting Scenarios 966
Document Information Panel 966
Creating an InfoPath Host Application 977
Creating an InfoPath Host Application in .NET 979
Host to InfoPath Communication 990
Handling Events from the Form 1001
Using the Host Property 1004
Submitting a Form to the Host 1007
Hosting the InfoPath Form Control in a Web Browser 1011
Host to InfoPath Communication 1020
InfoPath to Host Communication 1028
What’s Next? 1036
19 Building Custom Controls Using ActiveX Technologies 1037
Getting Started 1037
Installing and Using ActiveX Controls 1038
Adding an ActiveX Control to the Controls Task Pane 1038
Property Pages 1047
Building Custom Controls for InfoPath Using ActiveX 1049
Building an ActiveX Control for InfoPath Using C++ 1049
Building an ActiveX Control for InfoPath Using C# 1061
What’s Next? 1072
20 Add-ins 1073

Getting Started 1073
Introduction to COM Add-ins 1074
IDTExtensibility2 Interface 1075
Adding User Interface Items 1076
Building a COM Add-in for InfoPath 1076
OnConnection Method 1079
OnStartupComplete Method 1083
Event Handlers for Loading a Form 1088
Copy and Paste Button Event Handlers 1090
Contents xix
www.it-ebooks.info
Custom Task Panes 1093
Creating a Custom Task Pane 1093
Writing Add-ins and Custom Task Panes Using VSTO
2005 SE 1105
Implementing a Managed Add-in 1105
Adding a Custom Task Pane in a Managed Add-in 1108
Managing InfoPath Add-ins 1111
What’s Next? 1114
21 Importers and Exporters 1115
Getting Started 1115
Built-in Form Importers 1116
Importing a Form into InfoPath 1119
Fixing the Imported Form 1125
Post-Import Warnings 1126
Creating Your Own Form Importers and Exporters 1128
InfoPath Import/Export Framework 1128
How Post-Import Warnings Work 1140
Importing Form Data 1142
Data Importer Framework 1142

IInfoPathDataImporter Interface 1143
What’s Next? 1148
Appendix: Further Reading 1149
Index 1157
Contents
xx
www.it-ebooks.info
Figures
Figure P.1: Open With Form Template dialog lviii
Figure P.2: Dialog shown when InfoPath cannot find the Visual C# project
with the form code lx
Figure 1.1: Controls task pane in InfoPath 2003 8
Figure 1.2: Data Source task pane in InfoPath 2003 9
Figure 1.3: Insert Layout Table toolbar item 13
Figure 1.4: Tables toolbar 13
Figure 1.5: Fill Out a Form dialog in InfoPath 2003 SP1 17
Figure 1.6: Filling out a browser-enabled form template in Internet Explorer 18
Figure 1.7: Getting Started dialog 21
Figure 1.8: Design a Form Template dialog 22
Figure 2.1: Getting Started dialog 27
Figure 2.2: Design a Form Template dialog 28
Figure 2.3: New blank form 33
Figure 2.4: Layout task pane 35
Figure 2.5: Employment application form template with title added
by using Table with Title 36
Figure 2.6: Merge and split cells category of the Layout task pane 37
Figure 2.7: Employment application form template with cells for first
and last names 38
Figure 2.8: Employment application form template with a row for address
information 38

xxi
www.it-ebooks.info
Figure 2.9: Color Schemes task pane 40
Figure 2.10: Controls task pane 42
Figure 2.11: Employment application form template after adding standard
controls 46
Figure 2.12: Section control selected in design mode 47
Figure 2.13: Preview of the employment application form 48
Figure 2.14: Employment application form template with Optional
Section controls 50
Figure 2.15: Optional controls when previewing the form 51
Figure 2.16: Optional controls after clicking on the link, Click here to insert 51
Figure 2.17: Context menu for the Optional Section control when filling
out a form 52
Figure 2.18: Employment application form template with Repeating
Section control 53
Figure 2.19: Repeating Section control when previewing the form 54
Figure 2.20: Context menu for Repeating Section control when
previewing the form 54
Figure 2.21: Three instances of the Repeating Section control inserted
into the form 55
Figure 2.22: Insert Repeating Table dialog 57
Figure 2.23: Repeating Table control in design mode 57
Figure 2.24: Change To menu 58
Figure 2.25: Repeating Table control after changing from a Repeating
Section control 58
Figure 2.26: Repeating Table control when previewing the form 60
Figure 2.27: Horizontal Repeating Table control in design mode 61
Figure 2.28: Horizontal Repeating Table control when filling out a form 62
Figure 2.29: Insert Master/Detail dialog 63

Figure 2.30: Master and detail controls in design mode 63
Figure 2.31: Master/Detail control in the application review form
when filling out a form 64
Figure 2.32: Master/Detail control showing more applicant data 64
Figure 2.33: Binding design-time visual showing the name of the control 65
Figure 2.34: List controls in design mode 66
Figure 2.35: List controls when filling out a form 66
Figure 2.36: Multiple-Selection List Box control when filling out a form 67
Figures
xxii
www.it-ebooks.info
Figure 2.37: File Attachment control in design mode 68
Figure 2.38: File Attachment control when filling out a form 68
Figure 2.39: File Attachment control with résumé file attached 69
Figure 2.40: File Attachment control commands 69
Figure 2.41: Insert Picture Control dialog 71
Figure 2.42: Picture control when filling out the form 72
Figure 2.43: Picture control with picture inserted 72
Figure 2.44: Ink Picture control that contains text entered with
a Tablet PC stylus 73
Figure 2.45: Views task pane 74
Figure 2.46: Add View dialog 75
Figure 2.47: View Properties dialog 75
Figure 2.48: Font task pane 77
Figure 2.49: Selected Text Box control 78
Figure 2.50: Format Painter on the Standard toolbar 79
Figure 2.51: Format Painter cursor 80
Figure 2.52: Text Settings tab in the View Properties dialog 83
Figure 3.1: Clicking on a control in the view to select the bound control
in the data source 87

Figure 3.2: A Hyperlink control bound to
field1 in the data source, with a link
to the text of
field1 88
Figure 3.3: Warning dialog when changing the name of a data source field or group
for a published form 97
Figure 3.4: Data type validation error that occurs when a field contains
invalid data 100
Figure 3.5: Warning when saving a form with validation errors 100
Figure 3.6: Validation error for the cannot be blank property, delineated
by a red asterisk 102
Figure 3.7: Repeating
field4, which is bound to the Numbered List control
and repeats in
group1 104
Figure 3.8: Airline form with default value for
FlightType as
"Roundtrip" 106
Figure 3.9: The default value calculation button 107
Figure 3.10: The Insert Formula dialog, with a formula that sets this field’s default
value to today’s date plus 45 days 107
Figures xxiii
www.it-ebooks.info
Figure 3.11: Data source details for the FlightType field bound to the option
buttons in the airline form 108
Figure 3.12: Label for the node
PurposeOfVisit, created when inserting
the control into the view 118
Figure 3.13: Move Field or Group dialog used to move an existing field
or group 119

Figure 3.14: Validation error that appears when opening a form created before
the
FlightType–FlightDate node swap 121
Figure 3.15: Setting the
Employee group to repeat and reference itself 123
Figure 3.16: Filling out the MOI Company’s employee information form 124
Figure 3.17: Design a form from an existing XML document or schema instead
of creating the data source from scratch 125
Figure 3.18: Selecting the location of an XML document or schema 125
Figure 3.19: Choosing whether to include data from a selected XML file as the form
template default data 127
Figure 3.20: The first prompt when starting from an ambiguous schema 129
Figure 3.21: Disambiguating the data source by using the Edit Settings dialog 130
Figure 3.22: Prompt that appears when starting from a schema with multiple
top-level elements 131
Figure 3.23: The Type drop-down menu, with an option for adding a complete
XML Schema or XML document 134
Figure 3.24: Data source created from the XML document 136
Figure 3.25: Text Box Binding dialog that appears when Automatically create data
source is disabled or Change Binding is used from a control 139
Figure 3.26: Changing binding via the context menu by right-clicking on any control
that can be bound 140
Figure 3.27: Context menu of most popular control bindings 143
Figure 3.28: Dialog that results from clicking More on the menu shown
in Figure 3.27 143
Figure 3.29: Inserting
field1 in the data source 144
Figure 3.30: An absurd control nesting:
Attribute contains
DocumentElement, which contains Attribute 145

Figure 3.31:
NumberOfChildren attribute field, which is bound to both
the Optional Section and the Drop-Down List Box inside of the
Optional Section 146
Figures
xxiv
www.it-ebooks.info

×