1 / 24

Developing InfoPath Forms Using Managed Code

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.

sevita
Télécharger la présentation

Developing InfoPath Forms Using Managed Code

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Developing InfoPath Forms Using Managed Code David Gerhardt 3Sharp, LLC

  2. Problem Statement How can you use Visual Studio to add the power of managed code to your forms in a secure way?

  3. Rules Formulas Data Validation Data Connections Conditional Formatting XML Schema InfoPath Business Logic C# VB.NET Most Forms Do Not Need Code

  4. 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

  5. Visual Studio Integration

  6. .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

  7. Event Framework User Events Event Handlers OnLoad Open OnAfterChange OnClick OnValidate OnBeforeChange C# VB.NET JScript VBScript Edit OnSubmitRequest Submit Close

  8. Application Windows XDocuments User Window XDocument View Errors MailEnvelope DOM TaskPanes CommandBars Application lifecycle XDocument lifecycle Object Model Overview DataAdapters

  9. Document Object Model XMLDOM Form’s View sales name items item item units price

  10. Form Editing Events XMLDOM Event Handler sales OnAfterChange(DataDOMEvent e) name items Bubbling item item price units price

  11. 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

  12. Referencing Nodes With XPath XMLDOM sales /ns:sales /ns:sales/ns:items name items /ns:sales/ns:items/ns:item item item units price

  13. 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

  14. 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();

  15. 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

  16. 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

  17. 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

  18. 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

  19. 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

  20. 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

  21. 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()

  22. 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

  23. © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

More Related