Microsoft Office System UK Developers Conference Radisson Edwardian, Heathrow 29 th & 30 th June 2005
Developing InfoPath Forms Using Managed Code Jessica Gruber Microsoft Consulting Services
Problem Statement How can you use Visual Studio to add the power of managed code to your forms in a secure way?
InfoPath Business Logic Most Forms Do Not Need Code XML Schema Rules Formulas Data Validation Data Connections Conditional Formatting C# VB.NET
Machine Setup Developers – To create the form Visual Studio.NET 2003 InfoPath 2003 SP1 InfoPath Toolkit for Visual Studio.NET spx?FamilyId=7E9EBC57-E115-4CAC A712E22879BB&displaylang=en End Users – To fill out the form.Net Framework 1.1 InfoPath 2003 SP1
Visual Studio Integration
Form Template And Project Source Code (CS, VB) Project Definition (*PROJ) Form Template Files Visual Studio Project Assemblies (DLL and PDB) Template Definition (XSF) Default Data (XML) Schema (XSD) Views (XSLT) InfoPath Form Template (XSN) Publish / Preview Form Data User Fills Out Form.XML
Event Framework Open Edit Submit Close User C# VB.NET JScript VBScript Event Handlers OnLoad OnBeforeChange OnValidate OnAfterChange OnClick Events OnSubmitRequest
Windows XDocuments Application View Window Errors TaskPanes CommandBars MailEnvelope Application lifecycle XDocument lifecycle User XDocument DOM Object Model Overview DataAdapters
Document Object Model sales XMLDOM name items item priceunits Form’s View
Form Editing Events sales name items item priceunits price OnAfterChange(DataDOMEvent e) Bubbling Event Handler XMLDOM
Form Editing Events sales name items item priceunits price OnAfterChange(DataDOMEvent e) Bubbling Bubbling hides source Use e.Site and e.Source Events fire twice! Use e.Operation Check for “Insert” Event Handler XMLDOM
Referencing Nodes With XPath sales name items item priceunits XMLDOM /ns:sales/ns:items /ns:sales /ns:sales/ns:items/ns:item
Referencing Nodes With XPath sales name items item priceunits XMLDOM /ns:sales Namespaces Every node has one Prefix = short hand DOM and Node Methods selectSingleNode(Str) selectNodes(Str) Use “text” property DOM.selectSingleNode(“/ns:sales”);
Contains pre-configured Data Connections Supports all built in adapters Primary methods on each: Query / Submit DataAdapters da =thisXDocument.DataAdapters; // Query pre-configured web service ((WebServiceAdapter) da["My WS"]).Query(); // Submit to pre-configured WSS form library ((DAVAdapter) da["My SharePoint"]).Submit(); Data Adapters Collection
Offline Submit And Cache Offline Submit OnSubmitRequest If online, submit using DataAdapter Else, save XML locally OnLoad Swap each cached file with main DOM, and submit Example on MSDN: us/odc_ip2003_ta/html/odc_InfoPath_submitting_form s.asp?frame=true Offline Cache of Secondary Data Sources OnLoad If online, update cache with new local copies Else, use cached copies instead
Dynamic Help In Task Pane Use OnContextChange Event Update HTML in Task Pane Lab 14 shows how to do this in script /library/en- us/odc_ip2003_tr/html/odc_INF_Lab_14.asp /library/en- us/odc_ip2003_tr/html/odc_INF_Lab_14.asp Blogged how to do this in managed code 7/ aspx 7/ aspx CHM files also possible but not dynamic 7/ aspx 7/ aspx
Digital Signatures Bypass InfoPath Wizard to Sign Form Implement OnSign event (requires Full Trust) OM: SignedDataBlocks, Signatures, Certificate Remove the xml:lang attribute before signing Add and Validate Signatures on Server System.Security.Cryptography.Xml.SignedXml More info on MSDN: us/odc_ip2003_ta/html/ODC_INFDigitallySigningData2.asp us/odc_ip2003_ta/html/ODC_INFDigitallySigningData2.asp
Encryption And Decryption Scenario: sensitive values, not entire DOM Use System.Security.Cryptography When Encrypt during OnSaveRequest Decrypt during OnLoad Example on MSDN: us/odc_ip2003_ta/html/odc_InfoPath_extendin g_save.asp?frame=true
Security and Managed Code Form Template Trust Levels Restricted: No Managed Code Domain: LocalIntranet Policy Offline Submit and Data with IsolatedStorage Dynamic Help in Task Pane Full Trust: Install, Sign, or Add Code Group Use.NET Configuration snap-in Add “InfoPath Form Templates” code group Examples: Active Directory, WSE
Two Steps to Debug Full Trust Remove the publishURL from the XSF Use this script to register the template: strXSF = "C:\\...path…\manifest.xsf"; strName = "InfoPath.ExternalApplication"; oApp = WScript.CreateObject(strName); oApp.RegisterSolution(strXSF,"overwrite"); us/odc_ip2003_tr/html/odc_INF_Lab_15.asp
Quick Tips And OM Highlights Prevent user from deleting existing rows Use OnBeforeChange, e.ReturnStatus = false Open a form with parameters XDocuments.NewFromSolutionWithData() Or use command line: infopath.exe /new parameters.xml Suggesting a save location and name XDocument.UI.SetSaveAsDialogFileName() XDocument.UI.SetSaveAsDialogLocation()
Session Summary Most forms do not need code Events = hooks that plug into your code Gotchas: bubbling and double-firing Code against the DOM Different ways to implement security Resources: us/dnanchor/html/odc_ancInfo.asp?frame=true
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.