240 likes | 413 Views
Developing InfoPath Forms Using Managed Code . David Gerhardt 3Sharp, LLC. Problem Statement. How can you use Visual Studio to add the power of managed code to your forms in a secure way?. Rules Formulas Data Validation Data Connections Conditional Formatting. XML Schema.
E N D
Developing InfoPath Forms Using Managed Code David Gerhardt 3Sharp, LLC
Problem Statement How can you use Visual Studio to add the power of managed code to your forms in a secure way?
Rules Formulas Data Validation Data Connections Conditional Formatting XML Schema InfoPath Business Logic C# VB.NET Most Forms Do Not Need Code
Machine Setup • Developers – To create the form • Visual Studio .NET 2003 • InfoPath 2003 SP1 • InfoPath Toolkit for Visual Studio .NET • http://www.microsoft.com/downloads/details.aspx?FamilyId=7E9EBC57-E115-4CAC-9986-A712E22879BB&displaylang=en • End Users – To fill out the form • .Net Framework 1.1 • InfoPath 2003 SP1
.XML Form Template And Project Visual Studio Project Form Data Source Code (CS, VB) Project Definition (*PROJ) Form Template Files User Fills Out Form InfoPath Form Template (XSN) Assemblies (DLL and PDB) Template Definition (XSF) Default Data (XML) Schema (XSD) Views (XSLT) Publish / Preview
Event Framework User Events Event Handlers OnLoad Open OnAfterChange OnClick OnValidate OnBeforeChange C# VB.NET JScript VBScript Edit OnSubmitRequest Submit Close
Application Windows XDocuments User Window XDocument View Errors MailEnvelope DOM TaskPanes CommandBars Application lifecycle XDocument lifecycle Object Model Overview DataAdapters
Document Object Model XMLDOM Form’s View sales name items item item units price
Form Editing Events XMLDOM Event Handler sales OnAfterChange(DataDOMEvent e) name items Bubbling item item price units price
Form Editing Events XMLDOM Event Handler sales OnAfterChange(DataDOMEvent e) name items Bubbling • Bubbling hides source • Use e.Site and e.Source • Events fire twice! • Use e.Operation • Check for “Insert” item item price units price
Referencing Nodes With XPath XMLDOM sales /ns:sales /ns:sales/ns:items name items /ns:sales/ns:items/ns:item item item units price
Referencing Nodes With XPath XMLDOM sales /ns:sales DOM.selectSingleNode(“/ns:sales”); • Namespaces • Every node has one • Prefix = short hand name items • DOM and Node Methods • selectSingleNode(Str) • selectNodes(Str) • Use “text” property item item units price
Data Adapters Collection • 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();
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: • http://msdn.microsoft.com/library/en-us/odc_ip2003_ta/html/odc_InfoPath_submitting_forms.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 scripthttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_ip2003_tr/html/odc_INF_Lab_14.asp • Blogged how to do this in managed codehttp://blogs.msdn.com/infopath/archive/2004/09/27/234911.aspx • CHM files also possible but not dynamic http://blogs.msdn.com/infopath/archive/2004/09/07/226572.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:http://msdn.microsoft.com/library/default.asp?url=/library/en-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: • http://msdn.microsoft.com/library/en-us/odc_ip2003_ta/html/odc_InfoPath_extending_save.asp?frame=true
Security and Managed CodeForm 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
Remove the publishURL from the XSF Use this script to register the template: Two Steps to Debug Full Trust strXSF = "C:\\...path…\manifest.xsf"; strName = "InfoPath.ExternalApplication"; oApp = WScript.CreateObject(strName); oApp.RegisterSolution(strXSF,"overwrite"); http://msdn.microsoft.com/library/default.asp?url=/library/en-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: • http://blogs.msdn.com/infopath • http://msdn.microsoft.com/library/en-us/dnanchor/html/odc_ancInfo.asp?frame=true • http://blogs.3sharp.com/Blog/davidg
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.