Managed Code Development and Microsoft Office Mike Pelton MPelton@microsoft.com Stephen Turner STurner@microsoft.com Developer & Platform Group Microsoft Ltd. The slides for this event will be posted at: www.microsoft.com/uk/msdn/postevents MSDN Connection Get personalised info and a customised RSS feed The programming language(s) you’re interested in The technology area(s) you’re interested in The information you want View news, technical resources, events, webcasts and community information Sign up for MSDN Connection at: http://www.microsoft.com/uk/msdn Microsoft Technical Roadshow http://www.microsoft.com/uk/techroadshow Agenda 9:30 – 9:45 Introduction 9:45 – 11:00 Office and Managed Code (1) 11:00 – 11:15 Break 11:15 – 12:30 Office and Managed Code (2) 12:30 – 13:30 Lunch 13:30 – 14:45 Windows Forms II 14:45 – 15:00 Break 15:00 – 16:15 Deployment and Security Web Services & Offline/Online support Heavy Footprint Tough to Deploy Rich User Experience Broad Reach Developer Productivity DLL Hell Easy Change Management Ease of Deployment Responsive Device Adaptability Network Dependency Poor User Experience Rich UI Complex To Develop Smart clients are easily deployed and managed client applications that provide an adaptive and interactive experience by leveraging local resources and intelligently connecting to distributed data sources. General Information Work Flow Storage assistive XML, data or documents core content Server process Storage Server process Server Processing Office programs Create document Pre-populate template Search / extract Post-Office Processing Create content Analyze/review information Process documents Business workflow Collaborative work Publish/distribute/archive Microsoft Office 2003 Development Technologies Server-side Processing Information Access Base Programmability User Interaction Post-Office Processing XML VSTO v2005 data island Web services IBF Research services ADO.NET Web queries XML schema Data binding Object models Research task pane Doc. actions task pane Office U.I. Custom controls / U.I. Smart tags Smart documents XML Documents Data Morning Agenda (!!) A Plethora of Techniques The Research Pane Smart Tags Smart Documents XML in Office Visual Studio Tools for Office Visio InfoPath The Information Bridge Framework Visual Studio 2005 & Office Office Products are COM Servers Whatever happens, you’re bridging between your managed and Office’s unmanaged code Normal interop procedures and considerations apply! Primary Interop Assemblies Platform Invoke Using methods from unmanaged DLL’s Reflection Discovering the types to use at run-time Connecting to running instances Use P/Invoke to find running instances Using Accessible objects IAccessible interface increases accessibility to users AND code Excel Primary Interop Assembly Integrating Managed Code Calling managed code from VBA Programming the VB Editor (!) Using Windows Forms inside Office apps Using MIME Types COM Drag and Drop Calling Managed Code from VBA COM Callable Wrapper (CCW) Using MIME Types Using Windows Forms Drag & Drop Add Ins VBA Add Ins Easy to develop, but slow and vulnerable Excel XLL’s, Word WLL’s Fast in execution; small skill pool COM Add-Ins Fast; require COM skills Office 2000 or later Automation Add-ins Functions can be called from Excel formulas Excel XP or later A Simple Add In All the books you’ll ever need: Microsoft .NET Development for Microsoft Office By Andrew Whitechapel Office 2003 Research Library Searches information sources from within a document Returns rich content, forms, actions Open architecture via XML Web Services Registration and Query methods No code on the client Integrated across Office 2003 Word, Excel, PowerPoint, Outlook, etc. A number of out-of-the-box services Dictionary, etc. Built-in Services Local sources on the machine Thesaurus and translation Office 2003 research services Dictionary, encyclopedia, web search, stock quotes Partner research services Factiva, eLibrary, Gale, WorldLingo More are being added SharePoint Portal Server Custom Services Can build custom research services Development language and platform neutral Data agnostic If you can connect to it programmatically, the research pane can talk to it Based on established API Documented in Research Service SDK Uses Web Services and published XML Schemas for communication between Office and your research service Web Service Calls Registration and query Registration Request Registration Response Query Request Query Response Web Server A Simple Research Service A Better Way To Build Research Services Research Services Object Model Wrapper Simple library that wraps up the research services plumbing Provides strongly typed request and response objects for Registration() and Query() Allows developer to focus on business logic Source code available Managed code written with C# & .NET Framework 1.1 Allows for extensibility Smart Tags v2 Innovations Across All Office Applications Appears in more Office places: Access, PowerPoint, Outlook & Task Panes Internet Explorer (with tool from SDK) Innovations: Auto firing actions (to modify document) Cascading menus & dynamic menus Pattern matching without writing code Smart tags for XML Tokenization – huge benefit for Asian languages Smart Documents Task Pane User Reactive Guided Solutions Follows the user through the document Tightly integrated with XML schema mapping Provides contextual content, actions & help Customizable through VB6 or VS.NET Extension of the Smart Tags 2.0 API Secure auto deployment & update Highly secure, manifest-described deployment Document only contains the URL of the manifest Centralized versioning and self-maintaining A Simple Smart Document Other Smart Documents Vertigo Managed Smart Document Wrapper Smart Documents In .NET Free, full source, and unsupported http://vertigosoftware.com/wrapper Great FAQ! Installs new .NET Smart Document project types in Visual Studio.NET 2003 VB.NET, C# Word, Excel Wraps the ISmartDocument interface in a way familiar to .NET developers Object oriented, “event” driven XML config file defines controls, event handlers Hides the low level “plumbing” XML in Word & Excel 2003 Customer Defined XML Schema Mapping Work with data in a format that makes sense Visually relate XML elements to document parts Open or save just the data you need Apply XSLT to data input / output Submit directly to a web service Fully supports the W3C XSD standard But users do not have to know XML Word also supports full fidelity WordML Apps can produce or consume Word documents Solution Benefits With XML Documents 1 Improved Data Access 2 Business Process Efficiency Validated information Web service (loose coupled connection) + formatting + intelligent receipt 5 Efficient capture XML Document Assembly data XML structure formatting Context-specific assistance 4 Intelligent Applications Query Result save 3 •Text •Document •Fragment •Image Searching & Repurposing Content XML Electronic Forms Platform Gather information more flexibly and accurately Connect people, info and processes more effectively Develop & deploy information gathering solutions more easily XML HTTP SOAP WSDL UDDI BizTalk SQL ERP CRM Visual Studio Tools for the Microsoft Office System Our strategic tool for developing Office solutions Currently supports building document-centric solutions for Word and Excel 2003 VSTO makes Office development approachable to the profession developer Provides all the productivity of Visual Studio Provides all the power of the .NET Framework Leverages the skills of .NET developers VSTO solutions are secure and easy to deploy Based on .NET Code Access Security Online ClickOnce deployment model Visual Studio Tools for Office New Project Templates for VS.NET Extends .NET development to Office Application code is separate from document Flexible .NET code access security model Power of Office 2003 Code can run in Word and Excel Developer productivity of Visual Studio Write code in Visual Basic and Visual C# .NET Windows Forms presentation framework A “professional” development environment VSTO Examples What’s New In Visio 2003 Programmability Macro recorder Visio drawing control Managed code samples and tools for Visio 2003 SDK New events and automation Macro Recorder Document programmers VBA macro generation Records user interaction with drawing surface Records user interaction with Visio’s ShapeSheet Application programmers Learn how the Visio API works Learn Visio concepts like glue Visio Drawing Control ActiveX control for full Visio functionality Access to rich Visio API Single active document and window Multiple instances in a single application Integrated look and feel with host application Diagrams in context to application usage (form, web part, smart doc, web page) Programmatic control over drawing surface Mouse and keyboard events Drawing Control Properties Document property Window property HostID property SRC property PageSizingBehavior property NegotiateMenus property NegotiateToolbars property Returns underlying Visio; Document object Returns underlying Visio; Window object Returns or sets string that defines where to get registry settings Returns or sets the string for the file to load Indicates if the control should resize the page when the drawing is loaded into the control Indicates if the control does menu merging with the host container Indicate if the control does toolbar merging with the host container User Interface Customization Best practice: Complete UI customization Use your own context menus Use Visio events Respond to application events Also available: Visio application user interface “Activate” by setting BOTH NegotiateMenus and NegotiateToolbars properties to TRUE Do not menu merge with multiple simultaneous instances of the control OR in Internet Explorer Use IOleCommandTarget/DoCmd for C# and VB.NET (see MSDN for article and sample) Drawing Control Containers Microsoft Office XP (including Access) Microsoft Office 2003 (including Access) InfoPath 1.0 and 1.1 through Solution Pane SharePoint Portal through Web Parts Internet Explorer 5.5 and later Visual Studio 6.0 (VB, C++) Visual Studio.NET 2003 (VB.NET, C#) Drawing Control Licensing Required: Visio application install Minimal Install option for control only Typical Install for control and solutions No special licensing in addition to application license Full support for corporate deployments Will not initialize without Visio 2003 on the client machine Visio 2003 SDK Available on MSDN for free download! Developer tools Event Monitor, Persistent Events, Solution Publishing Shape Studio for custom shape development VS 6.0 and VS.NET wizards for Visio solutions Samples Extensive application samples (VB, VB.NET, C#) and managed code tutorial Library of reusable functions, classes and sub-routines (VB, VB.NET, C#) Some reasons to write code Capitalising on the .NET Framework Custom Data Connections External Automation Dynamic Task Panes Encryption Change Tracking and Logging Advanced Calculations and Validation Form Template and Project Visual Studio Project Source Code (CS, VB) Project Definition (*PROJ) Form Template Files InfoPath Form Template (XSN) Publish / Preview Assemblies (DLL and PDB) Template Definition (XSF) Default Data (XML) Schema (XSD) Views (XSLT) Form Data .XML Event Framework User Events Open OnLoad OnClick Edit OnAfterChange OnValidate OnBeforeChange Submit Close OnSubmitRequest Event Handlers C# VB.NET JScript VBScript Document Object Model XML DOM sales name items item units item price Form’s View Referencing Nodes w/ XPath XML DOM sales name /ns:sales items item units /ns:sales/ns:items item /ns:sales/ns:items/ns:item price Referencing Nodes w/ XPath XML DOM sales /ns:sales DOM.selectSingleNode(“/ns:sales”); Namespaces name Every node has one Prefix = short hand items DOM & Node Methods item units item price selectSingleNode(Str) selectNodes(Str) Use “text” property Object Model Overview Application Windows Window TaskPanes User XDocuments View XDocument MailEnvelope CommandBars DOM Errors DataObjects Application lifecycle XDocument lifecycle Information Bridge Framework Smart Clients Web Service-based architecture (SOA) Centralized metadata/UI server Runtime for smart tag / XML event initiation Windows Forms and task pane support Web Services Metadata Finance Web Services ERP CRM Information Bridge Architecture Development Only Office Application Information Bridge Runtime (Word, Excel, Outlook) (Office add-in) Attached Schema Task Pane Manager Smart Tag Office Integration Visual Studio Metadata Cache U.I. Rendering User Control Designer Metadata Designer U.I. (WinForm, XSLT) Client Server (SOAP) U.I. (WinForm, XSLT) Metadata Service CRM Customer Information Web Service Optional: Information Bridge Compliant Web Service Optional: Information Bridge Compliant Web Service Optional: Information Bridge Compliant SAP Legacy Application Aggregation Service Invoices Orders Web services Metadata Database Visual Studio 2005 Tools for Office Visual Studio .NET 2005 with Projects for Word, Excel and InfoPath Language support for VB .NET and C# Full access to the .NET Framework, Web services, ADO .NET, integrated debugging CLR-based security model Major focus on developer productivity Integrated design-time experience Support for managed controls “View” controls Managed Document Actions Pane Schema-based programming model New data caching capabilities Data island accessible in a server environment Improved deployment model Online ClickOnce deployment model Visual Studio Tools for Office 2.0 Document Data Island Using the Data Island Visual Studio Tools for Office provides the ability to cache data within documents Enables new server scenarios Pre-populates or extracts data, without having to program XML Excel or Word not instantiated Enables offline usage Uses cached lookup tables Requires no hidden sheets Document Data Island Example of Caching Data [Cached()] CustomerDataSet customerDataSet; void ThisDocument_Initialize(…) { if (customerDataSet == null) { customerDataSet = new CustomerDataSet(); dataAdapter.Fill(customerDataSet); } list1.DataSource = customerDataSet; } Document Data Island Requesting Data from a Server ASPX page Data Island User data Server-side code can pre-populate elements before sending to client Document Data Island Sending Data Back to a Server ASPX page Updated Data Cache Updated data A VSTO 2005 enabled document is posted to a server, data is extracted, and sent to corporate data sources Document Data Cache Using the ServerDocument class private void GetData() { string user = Request.ServerVariables("AUTH_USER"); ExpensesDataset dsExpenses = new ExpensesDataset(); ExpensesDataAdapter.Fill(dsExpenses, user); ServerDocument doc = new ServerDocument("expenses.xls"); CachedDataItem cdi = doc.CachedDataManifest.Views ["ExpensesWorksheet"].CachedData["Expenses"]; cdi.SerializeDataInstance(dsExpenses); doc.Save(); doc.Close(); Response.Write(doc); } Visual Studio Tools for Office 2.0 Server-Side Documents Visual Studio 2005 Tools for Office 2003 2005 Responsive UI - runs on local machine Responsive All the rich, UI features of Word and Excel Managed Document Actions task pane Rich User Experience Support for calling Web Services through the .NET Framework and Visual Studio Document solution can be designed to work offline Data caching capabilities (data island) Web Services & Offline/Online support All the productivity of Visual Studio Complete access to the .NET Framework Integrated design-time experience Developer Productivity View controls Managed controls Managed Document Actions task pane Ease of Deployment Schema-based programming model Document is linked to assembly; deployed to a share server No-touch deployment model used for assembly resolution Easy Change Management Online ClickOnce deployment model Resources http://msdn.microsoft.com/office/ The Definitive “Hello World” Managed Smart Documents Tutorial Microsoft Office 2003 Smart Documents SDK Research Services SDK How to: Install Office Primary Interop Assemblies Troubleshooting Office Error Messages http://vertigosoftware.com/wrapper Managed Smart Documents Wrapper Additional Information Post Events Site All information on past events, slide decks etc http://www.microsoft.com/uk/msdn/postevents The UK MSDN Site & Flash Local news, events, webcasts http://www.microsoft.com/uk/msdn Register to receive the bi-weekly MSDN Flash by email http://www.microsoft.com/uk/msdn/flash.aspx Try Visual Studio http://www.microsoft.com/vstudio/tryit Take a look at the Express products http://msdn.microsoft.com/express GotDotNet and ASP.NET – lots of excellent resources http://www.gotdotnet.com http://www.asp.net Morning Summary A Plethora of Techniques The Research Pane Smart Tags Smart Documents XML in Office Visual Studio Tools for Office Visio InfoPath The Information Bridge Framework Visual Studio 2005 & Office © 2003 Microsoft Limited. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary .