<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Beth Massi - Sharing the goodness that is VB : OBA</title><link>http://blogs.msdn.com/bethmassi/archive/tags/OBA/default.aspx</link><description>Tags: OBA</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Build WPF Data Controls for Outlook Addins Easily with VS2010</title><link>http://blogs.msdn.com/bethmassi/archive/2009/12/21/build-wpf-data-controls-for-outlook-addins-easily-with-vs2010.aspx</link><pubDate>Mon, 21 Dec 2009 22:14:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9939814</guid><dc:creator>Beth Massi</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9939814.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9939814</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9939814</wfw:comment><description>&lt;p&gt;Last post I showed &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/12/15/migrating-an-outlook-client-to-net-framework-4-in-visual-studio-2010.aspx" target="_blank"&gt;how to migrate our Northwind Outlook client to .NET 4 and Office 2010&lt;/a&gt;. This Outlook Add-in displays order history information in an adjoining form region so sales associates can see that data immediately when communicating with customers. When we &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/07/oba-part-2-building-and-outlook-client-against-lob-data.aspx" target="_blank"&gt;originally built this with Visual Studio 2008&lt;/a&gt;, we used a WPF user control to display the data so that we could better match the look and feel of Outlook 2007. However we had to manually figure out the colors we needed and bind the data to the controls by writing XAML by hand. &lt;/p&gt;  &lt;p&gt;Today I want to show how we can use drag &amp;amp; drop data binding and the new WPF designer in Visual Studio 2010 to quickly create this control &lt;strong&gt;without writing one line of XAML ourselves&lt;/strong&gt;. &lt;/p&gt;  &lt;h4&gt;Displaying WPF Controls in Form Regions with ElementHost&lt;/h4&gt;  &lt;p&gt;Office clients by default work with Windows Forms controls. If you &lt;a href="http://msdn.microsoft.com/en-us/library/bb386177(VS.100).aspx" target="_blank"&gt;create a new Form Region&lt;/a&gt; you can add any Windows form control from the toolbox onto it. If you want to add WPF controls you simply add what’s called an &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.elementhost.aspx" target="_blank"&gt;ElementHost control&lt;/a&gt; which you find in the WPF Interoperability tab on your toolbox. This allows you to select from and host WPF User Controls in your project.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/QuicklyBuildaWPFUserControlforanOutlookC_903D/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/QuicklyBuildaWPFUserControlforanOutlookC_903D/image_thumb.png" width="670" height="318" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;This is the same technique in VS2008 and VS2010. However, VS2010 makes it much easier to create the WPF User Control in the first place because you can now use the data sources window to design and data bind WPF controls. The WPF designer is also much easier to use. Let’s see how we can build a WPF control that displays Order information and have Visual Studio generate all the XAML we need automatically for us, and have it look good too.&lt;/p&gt;  &lt;h4&gt;Using the Data Sources Window with WPF&lt;/h4&gt;  &lt;p&gt;Let’s create a new WPF control called OrderHistoryDD where we’ll use drag &amp;amp; drop data binding from the data sources window. Project –&amp;gt; Add New Item, then select User Control (WPF). To view the data sources window select menu Data –&amp;gt; Show Data Sources. Because we already have added a service reference to our data service (which we built in &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/03/oba-part-1-exposing-line-of-business-data.aspx" target="_blank"&gt;part 1&lt;/a&gt;), you will see the client types that were generated for us appear in the data sources window. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/QuicklyBuildaWPFUserControlforanOutlookC_903D/image_6.png"&gt;&lt;img style="border-right-width: 0px; margin: 0px 10px 10px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" align="left" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/QuicklyBuildaWPFUserControlforanOutlookC_903D/image_thumb_2.png" width="228" height="476" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;We want to display three levels of related information to the user. Orders, the related Order Details and the related Product inventory information. If you are familiar with Windows Forms development using the data sources window here is the same. You can select which controls should be dropped onto the design surface by selecting the desired control in the dropdown. &lt;/p&gt;  &lt;p&gt;The controls that are available to you depend on which target framework you are using. Since we are targeting .NET Framework 4 then we have some new controls at our disposal namely the WPF DataGrid and the DatePicker. &lt;/p&gt;  &lt;p&gt;However, we are only displaying data to the user here (&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/12/oba-part-3-storing-and-reading-data-in-word-documents.aspx" target="_blank"&gt;new orders are handled as POs in Word&lt;/a&gt; and the &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/03/08/oba-part-4-building-an-excel-client-against-lob-data.aspx" target="_blank"&gt;editing is done by our shipping department in the Excel client&lt;/a&gt;) so we’ll select TextBox controls instead of the DatePicker control. I also only want to display the ShipName, OrderDate, RequiredDate and ShippedDate in the Order grid so for the rest of the fields you can select [None]. &lt;/p&gt;  &lt;p&gt;Now drag the Orders onto the WPF design surface and you will see those fields in the grid. By default it is anchored to the top and left of the control. Click on the arrow to the right of the grid to also anchor it to the right side so it will stretch.&lt;/p&gt;  &lt;p&gt;Since we are not allowing edits, in the Property window for the DataGrid, set the IsReadOnly property to &lt;em&gt;True&lt;/em&gt;. Also set the ColumnWidth property to &lt;em&gt;Auto&lt;/em&gt;. To modify the order in which the columns appear, click on the ellipsis (…) next to the Columns property to open up the columns editor. Here we can also set the data binding and formatting on our columns by selecting the Binding property and dropping down the editor. You’ll notice that the columns are already bound to the data based on what we specified in the data sources window. Expand Options and you’ll see some additional settings you can make on the Binding. For this example, set the String Format to a simple date for all three date columns. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/QuicklyBuildaWPFUserControlforanOutlookC_903D/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/QuicklyBuildaWPFUserControlforanOutlookC_903D/image_thumb_3.png" width="687" height="409" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;You can also set additional properties here like styles and widths, etc. Since we set the DataGrid Width to Auto, I’ll select each of the column’s widths here, right-click on the Width property and select “Reset value” so that they pick up the same setting. This means the cells will auto size to display all the data. &lt;/p&gt;  &lt;p&gt;Now we need to display the &lt;strong&gt;related &lt;/strong&gt;Order Details. To do this, back in the data sources window expand the Order Details &lt;strong&gt;under the Orders. &lt;/strong&gt;It’s very important you select the related Order Details under the Orders otherwise the user won’t see the Order Details change as they select the Order above. This sets up a master-detail binding when we do it this way. This time, just select drop controls as TextBoxes for Quantity and UnitPrice and drop the related Order Details DataDrid under the Orders DataGrid. We also want to display the ProductName here, but because that field is on the Product entity we will have to add a column and set up the binding to it in the Column editor instead. &lt;/p&gt;  &lt;p&gt;So click the Columns ellipsis button for the Order Details DataGrid in the Property window and then click the Add button to add a new column. Set the Header property to “Product”. Open up the Binding editor again and expand the Path section. Select Product then ProductName to set up the binding to that field.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/QuicklyBuildaWPFUserControlforanOutlookC_903D/image_10.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/QuicklyBuildaWPFUserControlforanOutlookC_903D/image_thumb_4.png" width="682" height="411" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Select the Bindings for Quantity and UnitPrice and expand the Options node to set the String Format for those columns to display as number and currency respectively.&lt;/p&gt;  &lt;p&gt;Now we want to display the inventory information for each Product selected on the Order Details. Same as before, in the data sources window expand the &lt;strong&gt;related &lt;/strong&gt;Product under the Order – Order Details. Select the dropdown on Product and select Details. Then select to drop Labels for just ProductName, UnitsInStock and UnitsOnOrder. Drag the Product onto the form under the Order Details DataGrid and it will create three labels bound to the corresponding fields on Product. It creates a Grid control (not to be confused with DataGrid) with two columns with the field labels on the left and the controls on the right. Dock the entire grid control to the bottom left by selecting the grid and then clicking on the dock arrow at the top. This will dock it to the bottom left. Next add an image control to the bottom right, select the Source property, and select the Northwind traders logo.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/QuicklyBuildaWPFUserControlforanOutlookC_903D/image_14.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/QuicklyBuildaWPFUserControlforanOutlookC_903D/image_thumb_6.png" width="520" height="390" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Notice that we haven’t typed any XAML at all to set any of this up so far. If you look in the generated XAML you will see all the control and data binding definitions. Visual Studio 2010 takes care of all of this for us. But we also want to set up some nice styles on the data grids. Let’s set the alternating row colors and set up a style in the control resources so that we can share it on both DataGrids. We don’t have to know XAML to do this either. &lt;/p&gt;  &lt;h4&gt;Styling the DataGrids and Sharing Style Resources&lt;/h4&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/QuicklyBuildaWPFUserControlforanOutlookC_903D/image_16.png"&gt;&lt;img style="border-right-width: 0px; margin: 0px 10px 10px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" align="left" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/QuicklyBuildaWPFUserControlforanOutlookC_903D/image_thumb_7.png" width="329" height="312" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;To quickly set up a nice gradient style shared on both data grids for alternating rows, select a DataGrid and then AlternatingRowBackground in the property window. This opens up the new &lt;a href="http://msdn.microsoft.com/en-us/library/dd394490(VS.100).aspx" target="_blank"&gt;Brush Editor&lt;/a&gt;. Select the third glyph at the top left for gradient. You can select the start and stop gradient colors with the color selector on the left but it’s much easier if you already have an application in mind that has the colors you want, just click the eyedropper in order to pick up any color on your desktop. &lt;/p&gt;  &lt;p&gt;After you set up the style how you like it, you can extract it from the DataGrid control into the user control resources so that you can share it on both grids. Click on the diamond next to the AlternatingRowBackground property and select &lt;a href="http://msdn.microsoft.com/en-us/library/dd394488(VS.100).aspx" target="_blank"&gt;Extract Value to Resource&lt;/a&gt;. Name the resource and then click OK to add it to the resources section of the user control.&lt;/p&gt;  &lt;p&gt;Now you can go to the other DataGrid, click that AlternatingRowBackground and select “Apply Resource”. Then you can select from SystemColors and Local resources that match. Expand Local and you will see the resource you just created. We could spend all day styling our DataGrids but the nice thing is we can do a lot without having to know XAML. &lt;/p&gt;  &lt;h4&gt;Hooking Up the Data to CollectionViewSource&lt;/h4&gt;  &lt;p&gt;Now we need to hook up our WPF user control onto the form region and load it with data from our data service. If you haven’t already done so, build the project and then on the EmailForm select the ElementHost and chose the OrderHistoryDD user control we just built. &lt;/p&gt;  &lt;p&gt;We already have written the the code to load the data into a List(Of Orders). The &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/07/oba-part-2-building-and-outlook-client-against-lob-data.aspx" target="_blank"&gt;same code we wrote for our VS2008 version here&lt;/a&gt; applies in VS2010. The only difference now is that we need to set the List(Of Orders) to the CollectionViewSource.Source property for the master view source, in this case it’s called OrdersViewSource. &lt;a href="http://blogs.msdn.com/bethmassi/archive/2008/11/07/loading-data-and-binding-controls-in-wpf-with-collectionviewsource.aspx" target="_blank"&gt;I’ve talked about CollectionViewSources for master-details before&lt;/a&gt;. You can see this in the XAML that was generated for us, as well as the related OrdersOrder_DetailsViewSource: &lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;UserControl.Resources&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;CollectionViewSource &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;OrdersViewSource&amp;quot; &lt;br /&gt;                          &lt;/span&gt;&lt;span style="color: red"&gt;d&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;DesignSource&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;d&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;DesignInstance &lt;/span&gt;&lt;span style="color: red"&gt;my&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Order&lt;/span&gt;&lt;span style="color: blue"&gt;, &lt;/span&gt;&lt;span style="color: red"&gt;CreateList&lt;/span&gt;&lt;span style="color: blue"&gt;=True}&amp;quot; /&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;CollectionViewSource &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;OrdersOrder_DetailsViewSource&amp;quot; &lt;br /&gt;                          &lt;/span&gt;&lt;span style="color: red"&gt;Source&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;=Order_Details, &lt;br /&gt;                                           &lt;/span&gt;&lt;span style="color: red"&gt;Source&lt;/span&gt;&lt;span style="color: blue"&gt;={&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource &lt;/span&gt;&lt;span style="color: red"&gt;OrdersViewSource&lt;/span&gt;&lt;span style="color: blue"&gt;}}&amp;quot; /&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Because the CollectionViewSources are chained together (similar to how Winforms BindingSources are set up), all we need to do is set the master’s Source property and all the controls will pick up their bindings properly. To make this easier, create a property on the OrderHistoryDD user control that exposes the OrdersViewSource. In the code-behind for the WPF user control:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Windows.Data&lt;br /&gt;&lt;span style="color: blue"&gt;Public Class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;OrderHistoryDD

    &lt;/span&gt;&lt;span style="color: blue"&gt;Public ReadOnly Property &lt;/span&gt;OrdersViewSource &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CollectionViewSource
        &lt;/span&gt;&lt;span style="color: blue"&gt;Get
            Return CType&lt;/span&gt;(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.Resources(&lt;span style="color: #a31515"&gt;&amp;quot;OrdersViewSource&amp;quot;&lt;/span&gt;), &lt;span style="color: #2b91af"&gt;CollectionViewSource&lt;/span&gt;)
        &lt;span style="color: blue"&gt;End Get
    End Property&lt;br /&gt;End Class&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Now in the code-behind for the form region (the FormRegionShowing event handler for EmailForm) change the line of code that sets the DataContext of the old user control and set the OrdersViewSource.Source property instead:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: green"&gt;'Load the data from the service
&lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;ordersList &lt;span style="color: blue"&gt;As New &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;(&lt;span style="color: blue"&gt;Of &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Order&lt;/span&gt;)(customerOrders)
&lt;span style="color: green"&gt;'Set this ordersList as the DataContext of our WPF user control:
'Me.OrderHistory1.DataContext = ordersList

'In VS2010 CollectionViewSources are used instead:
&lt;/span&gt;&lt;span style="color: blue"&gt;Me&lt;/span&gt;.OrderHistoryDD1.OrdersViewSource.Source = ordersList&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Now rebuild and run it to see your lovely new user control appear in Outlook:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/QuicklyBuildaWPFUserControlforanOutlookC_903D/image_22.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/QuicklyBuildaWPFUserControlforanOutlookC_903D/image_thumb_10.png" width="615" height="669" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;But something is missing. We want to display the line item and order totals in the grids. We could add a property onto the Order partial class, but we also want to sub-total each of the line items. Instead of adding read-only properties to the partial classes we can write one WPF value converter that handles both of these cases and then use that in our DataGrids. &lt;/p&gt;

&lt;h4&gt;Writing a Converter to Aggregate Totals&lt;/h4&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;I’ve talked about how to write a &lt;a href="http://blogs.msdn.com/bethmassi/archive/2008/12/12/formatting-data-in-wpf-controls.aspx" target="_blank"&gt;converter to format data in controls exactly how you like&lt;/a&gt;. In this case we want to write one that will take either a single Order_Detail to calculate the line item total or a collection of Order_Details to calculate the Order total. Here’s one way to do that.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Windows.Data
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;NorthwindOutlookClient.NorthwindService.NorthwindModel

&lt;span style="color: green"&gt;'Used by the OrderHistory WPF control to display line totals and Order total in the UI
&lt;/span&gt;&lt;span style="color: blue"&gt;Public Class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;OrderTotalConverter
    &lt;/span&gt;&lt;span style="color: blue"&gt;Implements &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IValueConverter

    &lt;/span&gt;&lt;span style="color: blue"&gt;Public Function &lt;/span&gt;Convert(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As Object&lt;/span&gt;, &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;targetType &lt;span style="color: blue"&gt;As &lt;/span&gt;System.&lt;span style="color: #2b91af"&gt;Type&lt;/span&gt;,
                            &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;parameter &lt;span style="color: blue"&gt;As Object&lt;/span&gt;,
                            &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;culture &lt;span style="color: blue"&gt;As &lt;/span&gt;System.Globalization.&lt;span style="color: #2b91af"&gt;CultureInfo&lt;/span&gt;) &lt;span style="color: blue"&gt;As Object &lt;/span&gt;_
                        &lt;span style="color: blue"&gt;Implements &lt;/span&gt;System.Windows.Data.&lt;span style="color: #2b91af"&gt;IValueConverter&lt;/span&gt;.Convert

        &lt;span style="color: blue"&gt;Dim &lt;/span&gt;total &lt;span style="color: blue"&gt;As Double &lt;/span&gt;= &lt;span style="color: brown"&gt;0.0
        &lt;/span&gt;&lt;span style="color: blue"&gt;If TypeOf &lt;/span&gt;value &lt;span style="color: blue"&gt;Is &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Order_Detail &lt;/span&gt;&lt;span style="color: blue"&gt;Then
            &lt;/span&gt;&lt;span style="color: green"&gt;'return the line item total
            &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;o = &lt;span style="color: blue"&gt;CType&lt;/span&gt;(value, &lt;span style="color: #2b91af"&gt;Order_Detail&lt;/span&gt;)
            total += o.Quantity * o.UnitPrice

        &lt;span style="color: blue"&gt;ElseIf TypeOf &lt;/span&gt;value &lt;span style="color: blue"&gt;Is &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IEnumerable&lt;/span&gt;(&lt;span style="color: blue"&gt;Of &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Order_Detail&lt;/span&gt;) &lt;span style="color: blue"&gt;Then
            &lt;/span&gt;&lt;span style="color: green"&gt;'return the order total
            &lt;/span&gt;&lt;span style="color: blue"&gt;For Each &lt;/span&gt;o &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Order_Detail &lt;/span&gt;&lt;span style="color: blue"&gt;In &lt;/span&gt;value
                total += o.Quantity * o.UnitPrice
            &lt;span style="color: blue"&gt;Next
        End If
        Return &lt;/span&gt;total
    &lt;span style="color: blue"&gt;End Function

    Public Function &lt;/span&gt;ConvertBack(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As Object&lt;/span&gt;,
                                &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;targetType &lt;span style="color: blue"&gt;As &lt;/span&gt;System.&lt;span style="color: #2b91af"&gt;Type&lt;/span&gt;,
                                &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;parameter &lt;span style="color: blue"&gt;As Object&lt;/span&gt;,
                                &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;culture &lt;span style="color: blue"&gt;As &lt;/span&gt;System.Globalization.&lt;span style="color: #2b91af"&gt;CultureInfo&lt;/span&gt;) &lt;span style="color: blue"&gt;As Object &lt;/span&gt;_
                            &lt;span style="color: blue"&gt;Implements &lt;/span&gt;System.Windows.Data.&lt;span style="color: #2b91af"&gt;IValueConverter&lt;/span&gt;.ConvertBack
        &lt;span style="color: blue"&gt;Return Nothing
    End Function
End Class&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Once you add this class rebuild the project. Now go back to the Order DataGrid and select Columns in the Property window to open the Column editor. Add a new TextBoxColumn, set the Header property to “Total” and then open up the Binding property. Set the Path to Order_Details and then expand Converter and select the NorthwindOutlookClient then OrderTotalConverter. Under Resources select “Create New…” and name and save the OrderTotalConverter in the resources section so you can select it on the Order_Details DataGrid. Expand Options and select the currency String Format. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/QuicklyBuildaWPFUserControlforanOutlookC_903D/image_26.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/QuicklyBuildaWPFUserControlforanOutlookC_903D/image_thumb_12.png" width="679" height="406" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Next Select the Order_Details DataGrid, add a new column, set the Header property to say “Total”. Select the Bindings property but this time don’t select anything for the Path. Expand Converter and select select the NorthwindOutlookClient then OrderTotalConverter and now in the Resources you will see OrderTotalConverter1, select that. Expand Options and select the currency String Format for this column as well. &lt;/p&gt;

&lt;p&gt;Now rebuild and run the project again. You can set a breakpoint on the Convert method and you will see that different value types are getting passed in depending on what DataGrid column is requesting the conversion. And best of all, now the user can see line item and order totals in the form region. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/QuicklyBuildaWPFUserControlforanOutlookC_903D/image_28.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/QuicklyBuildaWPFUserControlforanOutlookC_903D/image_thumb_13.png" width="606" height="264" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;As you can see Visual Studio 2010 has much improved RAD designers for data binding and styling business applications like this one. I’ve uploaded the &lt;a href="https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=OBANorthwind&amp;amp;ReleaseId=3712" target="_blank"&gt;source code which works with Visual Studio 2010 Beta 2 and Outlook 2010 Beta&lt;/a&gt; onto Code Gallery so have a look.&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9939814" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Article/default.aspx">Article</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Office/default.aspx">Office</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Data/default.aspx">Data</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2010/default.aspx">VS2010</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VSTO/default.aspx">VSTO</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/OBA/default.aspx">OBA</category></item><item><title>Migrating an Outlook Client to .NET Framework 4 in Visual Studio 2010</title><link>http://blogs.msdn.com/bethmassi/archive/2009/12/15/migrating-an-outlook-client-to-net-framework-4-in-visual-studio-2010.aspx</link><pubDate>Wed, 16 Dec 2009 07:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9937506</guid><dc:creator>Beth Massi</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9937506.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9937506</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9937506</wfw:comment><description>&lt;P&gt;Early this year we built a &lt;A href="http://code.msdn.microsoft.com/OBANorthwind" target=_blank mce_href="http://code.msdn.microsoft.com/OBANorthwind"&gt;business application for order management for Northwind Traders&lt;/A&gt; on the Office and SharePoint platform using Visual Studio 2008 and Office &amp;amp; SharePoint 2007. If you missed them:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/02/02/building-an-office-business-application-for-techready-8.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2009/02/02/building-an-office-business-application-for-techready-8.aspx"&gt;Architecture of the Northwind Office Business Application&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/02/03/oba-part-1-exposing-line-of-business-data.aspx" mce_href="http://blogs.msdn.com/bethmassi/archive/2009/02/03/oba-part-1-exposing-line-of-business-data.aspx"&gt;OBA Part 1 - Exposing Line-of-Business Data&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/02/07/oba-part-2-building-and-outlook-client-against-lob-data.aspx" mce_href="http://blogs.msdn.com/bethmassi/archive/2009/02/07/oba-part-2-building-and-outlook-client-against-lob-data.aspx"&gt;OBA Part 2 - Building an Outlook Client against LOB Data&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/02/12/oba-part-3-storing-and-reading-data-in-word-documents.aspx" mce_href="http://blogs.msdn.com/bethmassi/archive/2009/02/12/oba-part-3-storing-and-reading-data-in-word-documents.aspx"&gt;OBA Part 3 - Storing and Reading Data in Word Documents&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/03/08/oba-part-4-building-an-excel-client-against-lob-data.aspx" mce_href="http://blogs.msdn.com/bethmassi/archive/2009/03/08/oba-part-4-building-an-excel-client-against-lob-data.aspx"&gt;OBA Part 4 - Building an Excel Client against LOB Data&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;
&lt;DIV align=left&gt;&lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/04/21/oba-part-5-building-the-sharepoint-2007-workflow.aspx" mce_href="http://blogs.msdn.com/bethmassi/archive/2009/04/21/oba-part-5-building-the-sharepoint-2007-workflow.aspx"&gt;OBA Part 5 - Building the SharePoint 2007 Workflow&lt;/A&gt; &lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;The solution consists of an Outlook client that pulls up order history when a customer email arrives in the sales associate’s inbox. This way they don’t have to leave Outlook (the application that they live in all day) to see corresponding line-of-business (LOB) data, in this case order history, right in the email message. LOB data is exposed via a simple REST-based WCF data service (&lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/02/03/oba-part-1-exposing-line-of-business-data.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2009/02/03/oba-part-1-exposing-line-of-business-data.aspx"&gt;built in part 1&lt;/A&gt;) and is displayed in the reading pane in Outlook for each customer.&lt;/P&gt;
&lt;P&gt;Today I want to take a look at how we can migrate the &lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/02/07/oba-part-2-building-and-outlook-client-against-lob-data.aspx" mce_href="http://blogs.msdn.com/bethmassi/archive/2009/02/07/oba-part-2-building-and-outlook-client-against-lob-data.aspx"&gt;Outlook client we built in part 2&lt;/A&gt; to Office 2010 and &lt;A href="http://msdn.microsoft.com/en-us/library/cc656912(VS.100).aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/cc656912(VS.100).aspx"&gt;.NET Framework 4.0 Client Profile&lt;/A&gt; using Visual Studio 2010. The VSTO 4 Runtime has changed so there are some manual steps you may have to take when you migrate your solutions depending on what features you are using.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;I set up a Windows 7 VHD with Visual Studio, SharePoint &amp;amp; Office Betas that I’ll be using for development, just like I explained in this post - &lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/12/02/setting-up-windows-7-for-office-sharepoint-2010-beta-development.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2009/12/02/setting-up-windows-7-for-office-sharepoint-2010-beta-development.aspx"&gt;Setting up Windows 7 for Office &amp;amp; SharePoint 2010 Beta Development&lt;/A&gt;. If you’d like to follow along you can &lt;A href="http://code.msdn.microsoft.com/OBANorthwind" target=_blank mce_href="http://code.msdn.microsoft.com/OBANorthwind"&gt;download the Visual Studio 2008 version of the code here&lt;/A&gt;.&lt;/P&gt;
&lt;H4&gt;&lt;STRONG&gt;Required Changes for the New VSTO 4 Runtime&lt;/STRONG&gt;&lt;/H4&gt;
&lt;P&gt;First I want to point out some excellent information on MSDN that you should familiarize yourself with if you are migrating Office solutions built with Visual Studio (VSTO). All the samples, walkthroughs and videos on the &lt;A href="http://msdn.microsoft.com/en-us/vsto/ee676911.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/vsto/ee676911.aspx"&gt;Visual Studio 2010 resources page&lt;/A&gt; on the &lt;A href="http://msdn.com/vsto" target=_blank&gt;VSTO Dev Center&lt;/A&gt; are valuable but if you are migrating you should pay close attention to this item - &lt;/P&gt;
&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/vsto/ee207231(VS.100).aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/vsto/ee207231(VS.100).aspx"&gt;&lt;EM&gt;&lt;STRONG&gt;Migrating Office Solutions to the .NET Framework 4&lt;/STRONG&gt;&lt;/EM&gt;&lt;/A&gt;&lt;EM&gt; &lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;I also recommend familiarizing yourself with the new VSTO4 Runtime here - &lt;/P&gt;
&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/bb608603(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb608603(VS.100).aspx"&gt;&lt;STRONG&gt;&lt;EM&gt;Visual Studio Tools for Office Runtime Overview&lt;/EM&gt;&lt;/STRONG&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;In particular, if your Outlook project uses Form Regions or the Ribbon designer then you will have some work to do &lt;STRONG&gt;if you target .NET Framework 4 &lt;/STRONG&gt;because the VSTO 4 runtime has been updated to use Office object model interfaces and not directly inherit from classes like was done in the previous versions of the VSTO runtime. Moving forward this is a very good thing because it removes the dependency on specific versions of Office and enables Office solutions to use the new embedded interop types feature (sometimes referred to as “no-PIAs”) in the .NET Framework 4. This means solutions can run on end user computers without installing these primary interop assemblies (PIAs).&lt;/P&gt;
&lt;P&gt;So you may have to reach into the designer generated files and tweak some code. Note that depending on how you structure your application it may be easier after you retarget to .NET 4 to just create a new Form Region and a new Ribbon and copy your user code into them. This is especially true if you are migrating solutions using Visual Studio Beta 2 to .NET 4 because of a bug which I’ll show you how to work around. Let’s take a look at what we need to do for our &lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/02/07/oba-part-2-building-and-outlook-client-against-lob-data.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2009/02/07/oba-part-2-building-and-outlook-client-against-lob-data.aspx"&gt;Northwind Outlook client&lt;/A&gt;.&lt;/P&gt;
&lt;H4&gt;&lt;STRONG&gt;Migrating the Outlook Solution to Visual Studio 2010&lt;/STRONG&gt;&lt;/H4&gt;
&lt;P&gt;Before I jump into migrating this solution I should point out that building Office client solutions in Visual Studio became a lot easier starting in Visual Studio 2008 with all the designer support that was added directly into the Visual Studio box. You can create form regions, ribbons, and host WPF controls easily using these tools in VS2008 without having to install additional extensions. These tools have been updated in Visual Studio 2010 to allow you to build upon Office 2010 but they are just as easy to use.&lt;/P&gt;
&lt;P&gt;So let’s start with opening the NorthwindOutlookClient solution in Visual Studio 2010. The migration wizard will open and you’ll be guided through conversion of the project to VS2010. Note that depending on what you have installed on your development machine will determine what Visual Studio does with the solution. If you have the .NET 3.5 framework installed then the target framework will not change, however if you only have .NET 4 then it will update to that automatically. (For more information see &lt;A href="http://msdn.microsoft.com/en-us/library/4bez6837(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/4bez6837(VS.100).aspx"&gt;How to Upgrade Office Solutions&lt;/A&gt; and &lt;A href="http://msdn.microsoft.com/en-us/library/bb398242(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb398242(VS.100).aspx"&gt;Configuring a Computer to Develop Office Solutions&lt;/A&gt;). &lt;/P&gt;
&lt;P&gt;Since &lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/12/02/setting-up-windows-7-for-office-sharepoint-2010-beta-development.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2009/12/02/setting-up-windows-7-for-office-sharepoint-2010-beta-development.aspx"&gt;my development environment&lt;/A&gt; is a Windows 7 machine set up with Office 2010, Visual Studio 2010 and SharePoint Foundation 2010 I get some warnings immediately about the version of Office being wrong. “This project requires Microsoft Office Outlook 2007, but this application is not installed.” &lt;STRONG&gt;However it will build and run just fine in Outlook 2010&lt;/STRONG&gt;. &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MigratinganOutlookClienttoVisualStudio20_CB9A/image_6.png" mce_href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MigratinganOutlookClienttoVisualStudio20_CB9A/image_6.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MigratinganOutlookClienttoVisualStudio20_CB9A/image_thumb_2.png" width=599 height=529 mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MigratinganOutlookClienttoVisualStudio20_CB9A/image_thumb_2.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;H4&gt;&lt;STRONG&gt;Updating the Target Framework to .NET 4&lt;/STRONG&gt;&lt;/H4&gt;
&lt;P&gt;Now let’s change the target framework to .NET Framework 4 Client Profile. In Visual Basic you do this by selecting the project properties Compile tab, scroll down to “Advanced Compile Options…” and then select the new framework in the dropdown.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MigratinganOutlookClienttoVisualStudio20_CB9A/image_4.png" mce_href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MigratinganOutlookClienttoVisualStudio20_CB9A/image_4.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MigratinganOutlookClienttoVisualStudio20_CB9A/image_thumb_1.png" width=651 height=472 mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MigratinganOutlookClienttoVisualStudio20_CB9A/image_thumb_1.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;I should mention that the Client Profile is a subset of the full .NET 4 Framework meant for client applications like WPF, Windows Forms and Office solutions.&amp;nbsp; This means it’s a smaller install if your users don’t have the .NET Framework installed at all. It doesn’t include any server pieces like ASP.NET. This is also now the default framework target for &lt;STRONG&gt;new &lt;/STRONG&gt;Windows, WPF and Office projects.&lt;/P&gt;
&lt;P&gt;So once we change the framework, this will close and then reopen the project. Now we’ve got a bunch of stuff in our errors list. Ouch. There are 48 errors but only 25 of them are related to the VSTO 4 runtime changes. The minor problem is that the WPF control is referencing System.Xaml and when we switched the target this gets dropped (at least it does in Beta 2) so we need to just reference this 4.0 assembly. If you open up the OrderHistory.g.vb file, hover over the error, and drop down the error correction it will take care of this for you. &lt;/P&gt;
&lt;P&gt;Much more important is the 25 errors around our Form Region. We have two options, we can either add a brand new Form Region to the project, add our controls, paste our custom code into it, and delete the old one, or we can modify the designer generated code. In this case, because there is only one user control on the Form Region, it’s much easier to just create a new one. But if you have very complicated layouts you may need to take the route of updating the designer code to use the new interfaces. For the sake of learning what we need to do in these trickier situations, I’ll opt to go that route too. &lt;/P&gt;
&lt;H4&gt;&lt;STRONG&gt;Update Outlook Projects that Contain Form Regions&lt;/STRONG&gt;&lt;/H4&gt;
&lt;P&gt;Since we’ll be modifying the designer generated code you’ll need to make sure you click the &lt;A href="http://msdn.microsoft.com/en-us/library/26k97dbc.aspx#sectionToggle0" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/26k97dbc.aspx#sectionToggle0"&gt;Show All Files toolbar button on the Solution Explorer&lt;/A&gt;. Now we can open up the EmailForm.Designer.vb file in the editor. &lt;/P&gt;
&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/ee207231(VS.100).aspx#outlook" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ee207231(VS.100).aspx#outlook"&gt;This documentation contains the step-by-step code conversions that you need to perform to upgrade your form regions&lt;/A&gt;. First we need to modify the declaration of the form region class so that it derives from &lt;A href="http://msdn.microsoft.com/en-us/library/microsoft.office.tools.outlook.formregionbase(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/microsoft.office.tools.outlook.formregionbase(VS.100).aspx"&gt;FormRegionBase&lt;/A&gt; instead of FormRegionControl:&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class=code&gt;&amp;lt;System.ComponentModel.&lt;SPAN style="COLOR: #2b91af"&gt;ToolboxItemAttribute&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;False&lt;/SPAN&gt;)&amp;gt; _
&amp;lt;&lt;SPAN style="COLOR: blue"&gt;Global&lt;/SPAN&gt;.Microsoft.VisualBasic.CompilerServices.&lt;SPAN style="COLOR: #2b91af"&gt;DesignerGenerated&lt;/SPAN&gt;()&amp;gt; _
&lt;SPAN style="COLOR: blue"&gt;Partial Class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;EmailForm
    &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;Inherits &lt;/SPAN&gt;Microsoft.Office.Tools.Outlook.&lt;/STRONG&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&lt;STRONG&gt;FormRegionBase&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;The documentation also shows what the code looks like against a 3.5 target and what it should look like against a 4.0 target. For instance we have a problem with the constructor. In 3.5 we have:&lt;/P&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;    Public Sub New&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;formRegion &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Microsoft.Office.Interop.Outlook.FormRegion)
        &lt;SPAN style="COLOR: blue"&gt;MyBase&lt;/SPAN&gt;.New(formRegion)
        &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.InitializeComponent()
&lt;SPAN style="COLOR: blue"&gt;    End Sub&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;However in .NET 4 we need to change this to:&lt;/P&gt;&lt;PRE class=code&gt;    &lt;SPAN style="COLOR: blue"&gt;Public Sub New&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;formRegion &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Microsoft.Office.Interop.Outlook.FormRegion)
        &lt;SPAN style="COLOR: blue"&gt;MyBase&lt;/SPAN&gt;.New(&lt;SPAN style="COLOR: #2b91af"&gt;Globals&lt;/SPAN&gt;.Factory, formRegion)
        &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.InitializeComponent()
    &lt;SPAN style="COLOR: blue"&gt;End Sub&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Next we need update the signature of the InitializeManifest method (note that underscores are not necessary here in Visual Basic when targeting .NET Famework 4)&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Private Shared Sub &lt;/SPAN&gt;InitializeManifest(&lt;BR&gt;     &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;manifest &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Microsoft.Office.Tools.Outlook.&lt;SPAN style="COLOR: #2b91af"&gt;FormRegionManifest&lt;/SPAN&gt;,
     &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;factory &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Microsoft.Office.Tools.Outlook.&lt;SPAN style="COLOR: #2b91af"&gt;Factory&lt;/SPAN&gt;)&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;H4&gt;&lt;STRONG&gt;A Better Way to Upgrade (for now) – Working Around a Bug in Visual Studio 2010 Beta 2&lt;/STRONG&gt;&lt;/H4&gt;
&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/ee207231(VS.100).aspx#outlook" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ee207231(VS.100).aspx#outlook"&gt;Steps 5-8 of the documentation&lt;/A&gt; tell us to create a new Form Region to get the new factory code that we need -- this is why it may just be easier for you to start this way. Unfortunately there’s a bug in Visual Studio 2010 Beta 2 when you attempt to add a new item to the project it will select the wrong language. If you have a C# project it will select VB templates and if you have a VB project it will select C# templates. Doh! (Now that’s taking language parity thing a bit too far ;-)) So the way you have to work around this is to create a new Outlook Add-in project based on .NET 4 already and then add a new form region there. This is a bug only with migrated projects and it will be fixed in the final release. &lt;/P&gt;
&lt;P&gt;However, if you also want to keep building upon this solution in Beta 2, you should recreate the project, selecting a .NET 4 target, and add your existing files into it. This will ensure that things work smoothly going forward. You can actually name the project the same thing, you just need to put it into a different folder. Here’s how you do it.&lt;/P&gt;
&lt;P&gt;First &lt;STRONG&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/h2c9cdc0(VS.100).aspx#sectionToggle5" mce_href="http://msdn.microsoft.com/en-us/library/h2c9cdc0(VS.100).aspx#sectionToggle5"&gt;clean the solution to remove the registered Add-In&lt;/A&gt;&lt;/STRONG&gt;. From the menu select Build –&amp;gt; Clean NorthwindOutlookClient. &lt;/P&gt;
&lt;P&gt;Now since we have multiple projects in this solution you can right-click on the NorthwindOutlookClient in the Solution Explorer and then select Remove. Then close Visual Studio and open the folder where the NorthwindOutlookClient resides and rename that folder to NorthwindOutlookClient_OLD. Reopen the solution in Visual Studio. &lt;/P&gt;
&lt;P&gt;Next go to the main menu and select File –&amp;gt; Add –&amp;gt; New Project then make sure you select .NET Framework 4 and then choose Outlook 2010 Add-in and name it NorthwindOutlookClient. &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MigratinganOutlookClienttoVisualStudio20_CB9A/image_14.png" mce_href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MigratinganOutlookClienttoVisualStudio20_CB9A/image_14.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MigratinganOutlookClienttoVisualStudio20_CB9A/image_thumb_6.png" width=683 height=472 mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MigratinganOutlookClienttoVisualStudio20_CB9A/image_thumb_6.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Next right-click on the project and select Set as StartUp Project. Then Add –&amp;gt; Existing Item and select all the code, app.config, .xaml and .gif files in the NorthwindOutlookClient_OLD directory:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MigratinganOutlookClienttoVisualStudio20_CB9A/image_18.png" mce_href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MigratinganOutlookClienttoVisualStudio20_CB9A/image_18.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MigratinganOutlookClienttoVisualStudio20_CB9A/image_thumb_8.png" width=638 height=528 mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MigratinganOutlookClienttoVisualStudio20_CB9A/image_thumb_8.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;When prompted, say YES to overwrite ThisAddIn but say NO to overwrite ThisAddIn.Designer file. (Even though we didn’t select the designer file, it is automatically brought in when we select ThisAddin.) &lt;/P&gt;
&lt;P&gt;Next we need to re-add our Service Reference to our data service by right clicking and select Add –&amp;gt; Service Reference, click Discover button and then name the service the same thing, NorthwindService. &lt;/P&gt;
&lt;P&gt;Next make sure the .gif file is set to a Resource in the file properties. Select the file in the Solution Explorer and in the properties window set the Build Action to Resource.&lt;/P&gt;
&lt;P&gt;Finally, because we are using WPF controls in this solution, right-click and select Add Reference to add the .NET assembly references for System.Xaml, PresentationCore, PresentationFramework, WindowsBase and WindowsFormsIntegration.&lt;/P&gt;
&lt;H4&gt;&lt;STRONG&gt;Back to Migrating the Form Region&lt;/STRONG&gt;&lt;/H4&gt;
&lt;P&gt;Now you can get back to upgrading your Form Region as explained in &lt;A href="http://msdn.microsoft.com/en-us/library/ee207231(VS.100).aspx#outlook" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ee207231(VS.100).aspx#outlook"&gt;steps 5-8 &lt;/A&gt;. Add a new Form Region by selecting Project –&amp;gt; Add New Item and then selecting Form Region (now you’ll see the right templates). Walk through the wizard and then Show All Files again to open the designer generated file and grab the code for the two partial classes (note that the factory is an embedded class): &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MigratinganOutlookClienttoVisualStudio20_CB9A/image_12.png" mce_href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MigratinganOutlookClienttoVisualStudio20_CB9A/image_12.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MigratinganOutlookClienttoVisualStudio20_CB9A/image_thumb_5.png" width=462 height=492 mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MigratinganOutlookClienttoVisualStudio20_CB9A/image_thumb_5.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;It’s not too painful to change your original code once you get the right template for it. You just need to make sure that after you paste in these two partial classes, you update all instances of the class name with yours. In our case the name of the Form Region is EmailForm so the updated code back in the NorthwindOutlookClient project will look like this (I know it’s ugly that’s why it’s designer generated ;-). As an aside, look at where underscores are still necessary to resolve ambiguity if there is a line break):&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Partial Public Class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;EmailFormFactory
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Implements &lt;/SPAN&gt;Microsoft.Office.Tools.Outlook.&lt;SPAN style="COLOR: #2b91af"&gt;IFormRegionFactory

    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Public Event &lt;/SPAN&gt;FormRegionInitializing &lt;SPAN style="COLOR: blue"&gt;As  &lt;/SPAN&gt;_
        Microsoft.Office.Tools.Outlook.&lt;SPAN style="COLOR: #2b91af"&gt;FormRegionInitializingEventHandler

    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Private &lt;/SPAN&gt;_Manifest &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Microsoft.Office.Tools.Outlook.&lt;SPAN style="COLOR: #2b91af"&gt;FormRegionManifest

    &lt;/SPAN&gt;&amp;lt;System.Diagnostics.&lt;SPAN style="COLOR: #2b91af"&gt;DebuggerNonUserCodeAttribute&lt;/SPAN&gt;()&amp;gt; _
    &lt;SPAN style="COLOR: blue"&gt;Public Sub New&lt;/SPAN&gt;()
        &lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;._Manifest = &lt;SPAN style="COLOR: #2b91af"&gt;Globals&lt;/SPAN&gt;.Factory.CreateFormRegionManifest()
        &lt;SPAN style="COLOR: #2b91af"&gt;EmailForm&lt;/SPAN&gt;.InitializeManifest(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;._Manifest, &lt;SPAN style="COLOR: #2b91af"&gt;Globals&lt;/SPAN&gt;.Factory)
    &lt;SPAN style="COLOR: blue"&gt;End Sub

    &lt;/SPAN&gt;&amp;lt;System.Diagnostics.&lt;SPAN style="COLOR: #2b91af"&gt;DebuggerNonUserCodeAttribute&lt;/SPAN&gt;()&amp;gt; _
    &lt;SPAN style="COLOR: blue"&gt;ReadOnly Property &lt;/SPAN&gt;Manifest() &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Microsoft.Office.Tools.Outlook.&lt;SPAN style="COLOR: #2b91af"&gt;FormRegionManifest &lt;/SPAN&gt;_
             &lt;SPAN style="COLOR: blue"&gt;Implements &lt;/SPAN&gt;Microsoft.Office.Tools.Outlook.&lt;SPAN style="COLOR: #2b91af"&gt;IFormRegionFactory&lt;/SPAN&gt;.Manifest
        &lt;SPAN style="COLOR: blue"&gt;Get
            Return Me&lt;/SPAN&gt;._Manifest
        &lt;SPAN style="COLOR: blue"&gt;End Get
    End Property

    &lt;/SPAN&gt;&amp;lt;System.Diagnostics.&lt;SPAN style="COLOR: #2b91af"&gt;DebuggerNonUserCodeAttribute&lt;/SPAN&gt;()&amp;gt; _
   &lt;SPAN style="COLOR: blue"&gt;Function &lt;/SPAN&gt;CreateFormRegion(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;formRegion &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Microsoft.Office.Interop.Outlook.FormRegion) &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;_
             Microsoft.Office.Tools.Outlook.&lt;SPAN style="COLOR: #2b91af"&gt;IFormRegion &lt;/SPAN&gt;_
             &lt;SPAN style="COLOR: blue"&gt;Implements &lt;/SPAN&gt;Microsoft.Office.Tools.Outlook.&lt;SPAN style="COLOR: #2b91af"&gt;IFormRegionFactory&lt;/SPAN&gt;.CreateFormRegion&lt;/PRE&gt;&lt;PRE class=code&gt;        &lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;form &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;EmailForm &lt;/SPAN&gt;= &lt;SPAN style="COLOR: blue"&gt;New &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;EmailForm&lt;/SPAN&gt;(formRegion)
        form.Factory = &lt;SPAN style="COLOR: blue"&gt;Me
        Return &lt;/SPAN&gt;form
    &lt;SPAN style="COLOR: blue"&gt;End Function

    &lt;/SPAN&gt;&amp;lt;System.Diagnostics.&lt;SPAN style="COLOR: #2b91af"&gt;DebuggerNonUserCodeAttribute&lt;/SPAN&gt;()&amp;gt; _
    &lt;SPAN style="COLOR: blue"&gt;Function &lt;/SPAN&gt;GetFormRegionStorage(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;outlookItem &lt;SPAN style="COLOR: blue"&gt;As Object&lt;/SPAN&gt;,
                  &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;formRegionMode &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Microsoft.Office.Interop.Outlook.OlFormRegionMode,
                  &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;formRegionSize &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Microsoft.Office.Interop.Outlook.OlFormRegionSize) _&lt;BR&gt;             &lt;SPAN style="COLOR: blue"&gt;As Byte&lt;/SPAN&gt;() _&lt;BR&gt;             &lt;SPAN style="COLOR: blue"&gt;Implements &lt;/SPAN&gt;Microsoft.Office.Tools.Outlook.&lt;SPAN style="COLOR: #2b91af"&gt;IFormRegionFactory&lt;/SPAN&gt;.GetFormRegionStorage

        &lt;SPAN style="COLOR: blue"&gt;Throw New &lt;/SPAN&gt;System.&lt;SPAN style="COLOR: #2b91af"&gt;NotSupportedException&lt;/SPAN&gt;()
    &lt;SPAN style="COLOR: blue"&gt;End Function

    &lt;/SPAN&gt;&amp;lt;System.Diagnostics.&lt;SPAN style="COLOR: #2b91af"&gt;DebuggerNonUserCodeAttribute&lt;/SPAN&gt;()&amp;gt; _
    &lt;SPAN style="COLOR: blue"&gt;Function &lt;/SPAN&gt;IsDisplayedForItem(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;outlookItem &lt;SPAN style="COLOR: blue"&gt;As Object&lt;/SPAN&gt;,
                &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;formRegionMode &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Microsoft.Office.Interop.Outlook.OlFormRegionMode,
                &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;formRegionSize &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Microsoft.Office.Interop.Outlook.OlFormRegionSize) _
            &lt;SPAN style="COLOR: blue"&gt;As Boolean _&lt;BR&gt;            Implements &lt;/SPAN&gt;Microsoft.Office.Tools.Outlook.&lt;SPAN style="COLOR: #2b91af"&gt;IFormRegionFactory&lt;/SPAN&gt;.IsDisplayedForItem

        &lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;cancelArgs &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Microsoft.Office.Tools.Outlook.&lt;SPAN style="COLOR: #2b91af"&gt;FormRegionInitializingEventArgs &lt;/SPAN&gt;=
            &lt;SPAN style="COLOR: #2b91af"&gt;Globals&lt;/SPAN&gt;.Factory.CreateFormRegionInitializingEventArgs(outlookItem,
                                                                  formRegionMode,
                                                                  formRegionSize,
                                                                  &lt;SPAN style="COLOR: blue"&gt;False&lt;/SPAN&gt;)
        cancelArgs.Cancel = &lt;SPAN style="COLOR: blue"&gt;False
        RaiseEvent &lt;/SPAN&gt;FormRegionInitializing(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;, cancelArgs)
        &lt;SPAN style="COLOR: blue"&gt;Return Not &lt;/SPAN&gt;cancelArgs.Cancel
    &lt;SPAN style="COLOR: blue"&gt;End Function

    &lt;/SPAN&gt;&amp;lt;System.Diagnostics.&lt;SPAN style="COLOR: #2b91af"&gt;DebuggerNonUserCodeAttribute&lt;/SPAN&gt;()&amp;gt; _
    &lt;SPAN style="COLOR: blue"&gt;ReadOnly Property &lt;/SPAN&gt;Kind() &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Microsoft.Office.Tools.Outlook.&lt;SPAN style="COLOR: #2b91af"&gt;FormRegionKindConstants &lt;/SPAN&gt;_
             &lt;SPAN style="COLOR: blue"&gt;Implements &lt;/SPAN&gt;Microsoft.Office.Tools.Outlook.&lt;SPAN style="COLOR: #2b91af"&gt;IFormRegionFactory&lt;/SPAN&gt;.Kind
        &lt;SPAN style="COLOR: blue"&gt;Get
            Return &lt;/SPAN&gt;Microsoft.Office.Tools.Outlook.&lt;SPAN style="COLOR: #2b91af"&gt;FormRegionKindConstants&lt;/SPAN&gt;.WindowsForms
        &lt;SPAN style="COLOR: blue"&gt;End Get
    End Property
End Class
End Class

Partial Class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;WindowFormRegionCollection

    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Friend ReadOnly Property &lt;/SPAN&gt;EmailForm() &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;EmailForm
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Get
            For Each &lt;/SPAN&gt;Item &lt;SPAN style="COLOR: blue"&gt;As Object In Me
                If &lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;TypeOf &lt;/SPAN&gt;(Item) &lt;SPAN style="COLOR: blue"&gt;Is &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;EmailForm&lt;/SPAN&gt;) &lt;SPAN style="COLOR: blue"&gt;Then
                    Return CType&lt;/SPAN&gt;(Item, NorthwindOutlookClient.&lt;SPAN style="COLOR: #2b91af"&gt;EmailForm&lt;/SPAN&gt;)
                &lt;SPAN style="COLOR: blue"&gt;End If
            Next
            Return Nothing
        End Get
    End Property
End Class&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Now it looks like all our project errors have disappeared (thanks to Visual Basic’s background compiler). However if you didn’t create a brand new project like I explained above in order to work around that migration bug, then when you rebuild the solution you’ll see the build still fails. In this case we have one more thing to do.&lt;/P&gt;
&lt;H4&gt;&lt;STRONG&gt;Removing the SecurityTransparent Attribute &lt;/STRONG&gt;&lt;/H4&gt;
&lt;P&gt;The next section of the documentation on upgrading Office solutions has information on how to &lt;A href="http://msdn.microsoft.com/en-us/library/ee207231(VS.100).aspx#upgrade" mce_href="http://msdn.microsoft.com/en-us/library/ee207231(VS.100).aspx#upgrade"&gt;Remove the SecurityTransparent attribute from Office Projects that you upgrade from Visual Studio 2008&lt;/A&gt;. Under My Project node in the Solution Explorer, open up the AssemblyInfo file and you’ll see at the bottom the SecurityTransparent attribute. Remove that line of code. If you created a new project based on .NET 4 from the get-go this file will already be correct. &lt;/P&gt;
&lt;H4&gt;&lt;STRONG&gt;Run it!&lt;/STRONG&gt;&lt;/H4&gt;
&lt;P&gt;Now you should be able to rebuild the project and it will succeed. Hit F5 and now we have the Outlook client working and looking as before, but now we are targeting the .NET framework 4 and we have all the new features at our disposal. &lt;/P&gt;
&lt;P&gt;As you can see there are some manual steps to migrating Office solutions to the .NET Framework 4, but once you are familiar with the changes, it’s pretty straightforward. Keep in mind that if you are migrating your own solutions and you have code that loads form regions and/or ribbons dynamically at runtime you will also have to update that code as well to use the factory methods and interfaces instead of classes, &lt;A href="http://msdn.microsoft.com/en-us/library/ee207231(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/ee207231(VS.100).aspx"&gt;take a look at the documentation for details&lt;/A&gt;. Hopefully dealing with a little migration pain now will pay off in the long run to you and your users. &lt;/P&gt;
&lt;H4&gt;Resources&lt;/H4&gt;
&lt;P&gt;For more information on building Office solutions with Visual Studio please check out:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Office Development with Visual Studio Developer Center on MSDN = &lt;A href="http://msdn.com/vsto" mce_href="http://msdn.com/vsto"&gt;http://msdn.com/vsto&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;Visual Studio Tools for Office Team Blog = &lt;A href="http://blogs.msdn.com/vsto" mce_href="http://blogs.msdn.com/vsto"&gt;http://blogs.msdn.com/vsto&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/vsto/ee676911.aspx" mce_href="http://msdn.microsoft.com/en-us/vsto/ee676911.aspx"&gt;Visual Studio 2010 Resources&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;For more information on underscores in Visual Basic 10 in Visual Studio 2010 see:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://channel9.msdn.com/posts/funkyonex/No-More-Underscrores-in-Visual-Basic-10/" mce_href="http://channel9.msdn.com/posts/funkyonex/No-More-Underscrores-in-Visual-Basic-10/"&gt;No More Underscores in Visual Basic 10&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/vbasic/ee681551.aspx" mce_href="http://msdn.microsoft.com/en-us/vbasic/ee681551.aspx"&gt;How Do I: Use Implicit Line Continuation in Visual Basic 10?&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/vbasic/dd819153.aspx" mce_href="http://msdn.microsoft.com/en-us/vbasic/dd819153.aspx"&gt;Visual Basic 2010 Resources&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9937506" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Article/default.aspx">Article</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Office/default.aspx">Office</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2010/default.aspx">VS2010</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VSTO/default.aspx">VSTO</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/OBA/default.aspx">OBA</category></item><item><title>Office Development with Visual Studio Tutorial Series – Part 2</title><link>http://blogs.msdn.com/bethmassi/archive/2009/12/08/office-development-with-visual-studio-2008-tutorial-series-part-2.aspx</link><pubDate>Tue, 08 Dec 2009 18:51:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9934207</guid><dc:creator>Beth Massi</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9934207.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9934207</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9934207</wfw:comment><description>&lt;P&gt;Last month &lt;A href="https://mvp.support.microsoft.com/profile=169AE602-45EF-47E6-8868-CA3E91D0A1EE" mce_href="https://mvp.support.microsoft.com/profile=169AE602-45EF-47E6-8868-CA3E91D0A1EE"&gt;Robert Green&lt;/A&gt;, VSTO MVP, started a series of tutorials on building on Office 2007. Today we published part 2 of his step-by-step tutorials. Thanks Robert!&lt;/P&gt;
&lt;P&gt;In this second part of the series of tutorials on Office Business Applications, learn how to create a Word 2007 price quote generation solution using Visual Studio 2008. This tutorial shows you how to create a custom task pane to display data from a database and binding that data to content controls. This step-by-step tutorial also includes full source code in Visual Basic. Check out the tutorial on the &lt;A href="http://msdn.microsoft.com/en-us/vsto/ee620548.aspx" mce_href="http://msdn.microsoft.com/en-us/vsto/ee620548.aspx"&gt;VSTO Developer Center&lt;/A&gt;: &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;A href="http://msdn.microsoft.com/en-us/vsto/ee861194.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/vsto/ee861194.aspx"&gt;Building an Office Business Application Part 2 – Generating Automobile Quotes&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;And if you missed part 1:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/vsto/ee620548.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/vsto/ee620548.aspx"&gt;Building an Office Business Application Part 1 - Scheduling Customer Appointments&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;If you’re just getting started with Office development in Visual Studio, this is a great place to start.&lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9934207" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Community/default.aspx">Community</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Article/default.aspx">Article</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Office/default.aspx">Office</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VSTO/default.aspx">VSTO</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/OBA/default.aspx">OBA</category></item><item><title>SDC 2009 Recap &amp; Surprise</title><link>http://blogs.msdn.com/bethmassi/archive/2009/10/20/sdc-2009-recap-surprise.aspx</link><pubDate>Tue, 20 Oct 2009 13:39:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9909885</guid><dc:creator>Beth Massi</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9909885.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9909885</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9909885</wfw:comment><description>&lt;p&gt;&lt;a href="http://sdc.nl/" target="_blank"&gt;SDC09&lt;/a&gt; has been a blast. I just finished my last session on &lt;strong&gt;Building Office Business Applications with Visual Studio 2010&lt;/strong&gt; and I think it went well. We created an OBA for good old Northwind Traders. I migrated &lt;a href="http://code.msdn.microsoft.com/OBANorthwind " target="_blank"&gt;the 2008 code which is here on code gallery&lt;/a&gt; into VS 2010 and showed the new features of VS2010 that makes Office development easier focusing on RAD data binding (including WPF) and designers, new multi-project deployment, and SharePoint 2010 tools. &lt;/p&gt;  &lt;p&gt;My main goal was to provide a real-world scenario and architecture but keep the demo code manageable and simple while also introducing folks to all the RAD designers available. This way you can take apart the sample easily and reuse just the pieces you need. Check out the code and 5-part article series on how to build the Northwind OBA in Visual Studio 2008:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Code Download: &lt;a title="http://code.msdn.microsoft.com/OBANorthwind" href="http://code.msdn.microsoft.com/OBANorthwind"&gt;http://code.msdn.microsoft.com/OBANorthwind&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/03/oba-part-1-exposing-line-of-business-data.aspx"&gt;OBA Part 1 - Exposing Line-of-Business Data&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/07/oba-part-2-building-and-outlook-client-against-lob-data.aspx"&gt;OBA Part 2 - Building an Outlook Client against LOB Data&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/12/oba-part-3-storing-and-reading-data-in-word-documents.aspx"&gt;OBA Part 3 - Storing and Reading Data in Word Documents&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/03/08/oba-part-4-building-an-excel-client-against-lob-data.aspx"&gt;OBA Part 4 - Building an Excel Client against LOB Data&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/04/21/oba-part-5-building-the-sharepoint-2007-workflow.aspx"&gt;OBA Part 5 - Building the SharePoint Workflow&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I migrated the solutions to use Office 2010 and SharePoint 2010 for my presentation so once those Betas are available I’ll update the links with that code. Beta 2 for Visual Studio released yesterday so I got to show everyone the latest and greatest tools including SharePoint 2010 tooling. Some of the features that make Office development and deployment easier are covered in these walkthroughs:&lt;/p&gt;  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee342218(VS.100).aspx"&gt;Office Programming (C# and Visual Basic)&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee317478(VS.100).aspx"&gt;Embedding Type Information from Microsoft Office Assemblies (C# and Visual Basic)&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd465290(VS.100).aspx"&gt;Deploying Multiple Office Solutions in a Single ClickOnce Installer&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd465291(VS.100).aspx"&gt;Copying a Document to the End User Computer after a ClickOnce Installation&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/vstudio/dd441784.aspx#Sharepoint" target="_blank"&gt;SharePoint Development in Visual Studio 2010&lt;/a&gt; &lt;/li&gt;  &lt;p&gt;Yesterday my talks went really well too but I’ve done them many times before, last time being code camp. I did one on &lt;strong&gt;VB10 / C#4 language features&lt;/strong&gt; which are covered in these walkthroughs on MSDN:&lt;/p&gt;  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee461504(VS.100).aspx"&gt;Creating and Using Dynamic Objects (C# and Visual Basic)&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd409610(VS.100).aspx"&gt;Embedding Types from Managed Assemblies (C# and Visual Basic)&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd264738(VS.100).aspx"&gt;Use Named and Optional Arguments in Office Programming (C# Programming Guide)&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd293646(VS.100).aspx"&gt;Create a Collection Used by a Collection Initializer&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd293683(VS.100).aspx"&gt;Create an Add Extension Method Used by a Collection Initializer&lt;/a&gt;&amp;#160;&lt;/li&gt;  &lt;p&gt;I also did a talk on using&lt;strong&gt; Open XML and LINQ to XML&lt;/strong&gt; to manipulate Office 2007 document formats.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/08/17/devproconnections-article-taking-advantage-of-linq-and-xml-in-microsoft-office-2007.aspx"&gt;Article: Taking Advantage of LINQ and XML in Microsoft Office 2007&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/09/23/mail-merging-into-a-single-word-document-using-xml-literals.aspx"&gt;Article: Mail Merging Into a Single Word Document Using XML Literals&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/09/24/merging-text-photos-into-a-word-document-using-open-xml-sdk.aspx"&gt;Article: Merging Text &amp;amp; Photos into a Word Document using Open XML SDK&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/04/07/dnrtv-showing-off-the-open-xml-sdk-and-linq.aspx"&gt;Screencast: Showing off the Open XML SDK and LINQ &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/04/20/dnrtv-more-fun-with-office-and-xml-literals.aspx"&gt;Screencast: More Fun with Office and XML Literals &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Code: &lt;a href="http://code.msdn.microsoft.com/openxmlvb"&gt;Working with Open XML in Visual Basic&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;Happy Birthday!&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Yes it’s my birthday today. Not really an important one in my opinion, I’m just getting old I guess ;-). But when I showed up in my session this morning the room had been decorated with rainbow streamers. It was very cute and I thought that was the end of it. But afterwards during lunch I was lead onto the stage in the main hall and properly embarrassed by the event organizers. They brought out a cake with a gigantic fire-cracker on it! Then all the attendees sang happy birthday to me in Dutch.&amp;#160; It was totally embarrassing but also incredible to feel loved by the Dutch developer community :-). &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/SDC2009Recap_D346/IMG_1938.jpg" target="_blank"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="IMG_1938" border="0" alt="IMG_1938" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/SDC2009Recap_D346/IMG_1938_thumb.jpg" width="219" height="164" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/SDC2009Recap_D346/IMG_1936.jpg" target="_blank"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="IMG_1936" border="0" alt="IMG_1936" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/SDC2009Recap_D346/IMG_1936_thumb.jpg" width="220" height="166" /&gt;&lt;/a&gt;&amp;#160;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/SDC2009Recap_D346/IMG_1940.jpg" target="_blank"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="IMG_1940" border="0" alt="IMG_1940" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/SDC2009Recap_D346/IMG_1940_thumb.jpg" width="217" height="164" /&gt;&lt;/a&gt; &lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/SDC2009Recap_D346/37335777_2.jpg" target="_blank"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="37335777" border="0" alt="37335777" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/SDC2009Recap_D346/37335777_thumb.jpg" width="424" height="319" /&gt;&lt;/a&gt; &lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/SDC2009Recap_D346/37340197_2.jpg" target="_blank"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="37340197" border="0" alt="37340197" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/SDC2009Recap_D346/37340197_thumb.jpg" width="239" height="319" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;THANKS TO ALL OF YOU!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9909885" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Speaking/default.aspx">Speaking</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Community/default.aspx">Community</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VSTO/default.aspx">VSTO</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/OBA/default.aspx">OBA</category></item><item><title>Using Windows Presentation Foundation in Office Clients</title><link>http://blogs.msdn.com/bethmassi/archive/2009/08/10/using-windows-presentation-foundation-in-office-clients.aspx</link><pubDate>Tue, 11 Aug 2009 03:31:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9863656</guid><dc:creator>Beth Massi</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9863656.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9863656</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9863656</wfw:comment><description>&lt;p&gt;&lt;img style="display: inline; margin: 0px 10px 10px 0px" src="http://www.sdn.nl/Portals/0/Upload/Images/2009/Website/VP101.png" align="left" /&gt; I was cleaning up my desk today and in the piles of mail and gobs of paper I found the &lt;a href="http://www.sdn.nl/SDN/Magazine/tabid/66/articleType/ArticleView/articleId/2870/SDN-Magazine-101-Women-In-Technology-is-uit.aspx" target="_blank"&gt;SDN Magazine “Women in Technology” issue 101&lt;/a&gt; that featured an article I wrote that was released in print back in May. Well, I just noticed today that near the end of June they made most of the articles available online, including mine. :-)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.sdn.nl/SDN/Artikelen/tabid/58/agentType/View/PropertyID/2982/Default.aspx"&gt;&lt;strong&gt;Using Windows Presentation Foundation and Line-of-Business Data in Microsoft Office Clients&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In this article I talk about how to expose Line-of-Business data via ADO.NET Data Services to an Excel client using WPF. Office solutions you build with Visual Studio are designed to work with Windows Forms controls but you can also use WPF controls in your solutions as well. Any UI element that can host Windows Forms controls in an Office solution (VSTO) can also host WPF controls using the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.elementhost.aspx" target="_blank"&gt;Winforms ElementHost&lt;/a&gt; as a container. &lt;/p&gt;  &lt;p&gt;Using WPF controls in Office allows you to think out of the box and provide world-class data visualizations that are not possible with Windows Forms controls. And you can do it easily in an instantly familiar end-user application like those in the Office family. But what if you don’t have any fancy data visualizations? Even the simplest controls that display data are often better off as WPF controls in Office applications because they better match the UI styles used in the latest versions of Office. Using WPF can make your add-ins look built into the Office applications themselves, providing a better user experience.&lt;/p&gt;  &lt;p&gt;This article describes one piece of the Northwind Office Business Application (OBA) we created in the beginning of the year so if you’re interested in OBA development with Outlook, Word, Excel and Sharepoint I’d suggest reading these as well:&lt;/p&gt;  &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/03/oba-part-1-exposing-line-of-business-data.aspx"&gt;OBA Part 1 - Exposing Line-of-Business Data&lt;/a&gt;&lt;/li&gt;  &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/07/oba-part-2-building-and-outlook-client-against-lob-data.aspx"&gt;OBA Part 2 - Building and Outlook Client against LOB Data&lt;/a&gt;&lt;/li&gt;  &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/12/oba-part-3-storing-and-reading-data-in-word-documents.aspx"&gt;OBA Part 3 - Storing and Reading Data in Word Documents&lt;/a&gt;&lt;/li&gt;  &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/03/08/oba-part-4-building-an-excel-client-against-lob-data.aspx"&gt;OBA Part 4 - Building an Excel Client against LOB Data&lt;/a&gt;&lt;/li&gt;  &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/04/21/oba-part-5-building-the-sharepoint-2007-workflow.aspx"&gt;OBA Part 5 - Building the SharePoint 2007 Workflow&lt;/a&gt;&lt;/li&gt;  &lt;p&gt;The full sample application, built with Visual Studio 2008, is here: &lt;a title="http://code.msdn.microsoft.com/OBANorthwind" href="http://code.msdn.microsoft.com/OBANorthwind"&gt;http://code.msdn.microsoft.com/OBANorthwind&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Of course, the rest of the magazine is pack full of awesome articles from very well known women in technology (scroll to the bottom of &lt;a href="http://www.sdn.nl/SDN/Magazine/tabid/66/articleType/ArticleView/articleId/2870/SDN-Magazine-101-Women-In-Technology-is-uit.aspx" target="_blank"&gt;this page&lt;/a&gt; for the whole list). I’m honored to be featured with them in this issue. Thanks again to &lt;a href="http://information-worker.org/aboutus.aspx" target="_blank"&gt;Marianne van Wanrooij&lt;/a&gt; and the folks at &lt;a href="http://www.sdn.nl" target="_blank"&gt;SDN&lt;/a&gt; for putting this together and I’ll see you &lt;a href="http://www.sdc.nl/" target="_blank"&gt;in October at the SDN Conference&lt;/a&gt;!&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9863656" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Article/default.aspx">Article</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/XML/default.aspx">XML</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Office/default.aspx">Office</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/ADO.NET+Data+Services/default.aspx">ADO.NET Data Services</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VSTO/default.aspx">VSTO</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/OBA/default.aspx">OBA</category></item><item><title>OBA Part 5 - Building the SharePoint 2007 Workflow</title><link>http://blogs.msdn.com/bethmassi/archive/2009/04/21/oba-part-5-building-the-sharepoint-2007-workflow.aspx</link><pubDate>Wed, 22 Apr 2009 08:06:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9561302</guid><dc:creator>Beth Massi</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9561302.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9561302</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9561302</wfw:comment><description>&lt;p&gt;In my last few app building posts we've been building a simple Office Business Application (OBA) for the new Northwind Traders. If you missed them:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/03/oba-part-1-exposing-line-of-business-data.aspx"&gt;OBA Part 1 - Exposing Line-of-Business Data&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/07/oba-part-2-building-and-outlook-client-against-lob-data.aspx"&gt;OBA Part 2 - Building and Outlook Client against LOB Data&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/12/oba-part-3-storing-and-reading-data-in-word-documents.aspx"&gt;OBA Part 3 - Storing and Reading Data in Word Documents&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/03/08/oba-part-4-building-an-excel-client-against-lob-data.aspx" target="_blank"&gt;OBA Part 4 - Building an Excel Client against LOB Data&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Today we're going to build out the SharePoint workflow using Visual Studio 2008 SharePoint 2007 workflow templates. There's a plethora of &lt;a href="http://msdn.microsoft.com/en-us/library/bb386211.aspx" target="_blank"&gt;information on building these in the MSDN library&lt;/a&gt;. In order to develop against SharePoint you will need to set up your development environment properly so I &lt;a href="http://msdn.microsoft.com/en-us/library/cc160738.aspx" target="_blank"&gt;would read this first&lt;/a&gt; if you're just getting started. My SharePoint development environment is a 32bit Windows 2008 Server running MOSS 2007 and Visual Studio Professional 2008 Service Pack 1. &lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/OBASPDiagram1_4.jpg"&gt;&lt;img title="OBASPDiagram1" style="border-right: 0px; border-top: 0px; display: inline; margin: 10px 0px 0px 5px; border-left: 0px; border-bottom: 0px" height="342" alt="OBASPDiagram1" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/OBASPDiagram1_thumb_1.jpg" width="420" align="right" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If you recall &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/02/building-an-office-business-application-for-techready-8.aspx"&gt;our architecture diagram of our Northwind Traders OBA&lt;/a&gt; involved our Sales Reps submitting purchase orders as Word 2007 documents up to SharePoint which kicked off a workflow to parse the document and update the database with the order data through our data service. This allows us to store the unstructured document on SharePoint and the structured order data in our database. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/12/oba-part-3-storing-and-reading-data-in-word-documents.aspx" target="_blank"&gt;In Part 3&lt;/a&gt; we built the code that does the parsing of the document, now we just need to get that code into our workflow. We’ll also build in a delay so that the workflow can check the database later to see if the order has been shipped and update the status appropriately. We’ll also take advantage of SharePoint’s workflow history and task list to report outcomes or any issues that may arise.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Creating a Document Library for the Purchase Order Documents&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;For this example we need to add a document library called &lt;em&gt;Orders &lt;/em&gt;for the purchase order documents that are submitted. To create the document library, navigate to your SharePoint site and then in the right-had upper corner drop down the Site Actions, select Create (or just navigate to /_layouts/create.aspx) and then under Libraries select &lt;em&gt;Document Library. &lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA1A_2.jpg"&gt;&lt;img title="SPOBA1A" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="386" alt="SPOBA1A" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA1A_thumb.jpg" width="661" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The only other property that I changed here is the document template, change that to &lt;em&gt;Microsoft Office Word Document &lt;/em&gt;and then hit the Create button. This will bring you to the doc library and you’ll see the default fields in the column headers. We’re going to need to modify these to show the Order Status, an Order Number, the Shipped Date and the email address of the Sales Rep that submitted the order.&lt;/p&gt;  &lt;p&gt;Click on Settings then select &lt;em&gt;Create column&lt;/em&gt; to create new columns for the orders in the document library. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA2A_2.jpg"&gt;&lt;img title="SPOBA2A" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="443" alt="SPOBA2A" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA2A_thumb.jpg" width="659" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;For this example I added the following columns:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;em&gt;Order Status&amp;#160; &lt;br /&gt;&lt;/em&gt;Choice (New, Processed, Shipped, On Hold, Canceled)       &lt;br /&gt;Required = &lt;b&gt;No        &lt;br /&gt;&lt;/b&gt;Default = New       &lt;br /&gt;Add to Default View &lt;/li&gt;    &lt;li&gt;&lt;em&gt;Order Number&lt;/em&gt;       &lt;br /&gt;Single line of text       &lt;br /&gt;Required = &lt;b&gt;No&amp;#160; &lt;br /&gt;&lt;/b&gt;Add to Default View &lt;/li&gt;    &lt;li&gt;&lt;em&gt;Shipped Date        &lt;br /&gt;&lt;/em&gt;Date Only (no Time)       &lt;br /&gt;Required = &lt;strong&gt;No        &lt;br /&gt;&lt;/strong&gt;Add to Default View &lt;/li&gt;    &lt;li&gt;&lt;em&gt;Sales Rep Email        &lt;br /&gt;&lt;/em&gt;Single line of text       &lt;br /&gt;Required = &lt;b&gt;Yes&amp;#160; &lt;br /&gt;&lt;/b&gt;Add to Default View &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA3A_2.jpg"&gt;&lt;img title="SPOBA3A" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="419" alt="SPOBA3A" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA3A_thumb.jpg" width="596" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;After I added these columns I added a new default view to display them in the order I want. Click on the Settings again and select C&lt;em&gt;reate view.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA4_2.jpg"&gt;&lt;img title="SPOBA4" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="200" alt="SPOBA4" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA4_thumb.jpg" width="647" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The only thing the user is required to fill out when they upload a new purchase order document is the sales rep’s email address. (Recall that we added this field to the database &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/03/oba-part-1-exposing-line-of-business-data.aspx" target="_blank"&gt;when we built the data service&lt;/a&gt;). The Order Status and Shipped Date will actually be filled out automatically by the workflow depending on whether the order is new or has been updated by the Excel client (&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/03/08/oba-part-4-building-an-excel-client-against-lob-data.aspx" target="_blank"&gt;which we built in the last OBA post&lt;/a&gt;) that the shipping department uses to mark orders as shipped. Order Number will also be assigned by the workflow. We’ll use this to correlate the data with the purchase order document here in the list so we’ll need to add this field to the database. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Adding the Order Number to Northwind &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;So now we have the document library set up, we’re almost ready to write the workflow. First we’ll need to add the OrderNumber field to the Orders table in the Northwind database and then refresh our data service service so that this starts to show up as an available field on the Order. &lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;USE &lt;/span&gt;Northwind
GO

&lt;span style="color: blue"&gt;ALTER TABLE &lt;/span&gt;dbo.Orders &lt;span style="color: blue"&gt;ADD
    &lt;/span&gt;OrderNumber &lt;span style="color: blue"&gt;nvarchar&lt;/span&gt;(25) &lt;span style="color: blue"&gt;NULL
&lt;/span&gt;GO&lt;/pre&gt;

&lt;p&gt;In order to pick up this new field we need to refresh the Entity Data Model behind our data service. In the NorthwindDataService project open the NorthwindModel.edmx and then right-click on the design surface and select &lt;em&gt;Refresh from database. &lt;/em&gt;This will pick up the OrderNumber field on the Order entity. Rebuild the data service. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Options on Hosting the Data Service for Workflow Development&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you’ve been following along and playing with &lt;a href="http://code.msdn.microsoft.com/OBANorthwind"&gt;the sample&lt;/a&gt;, you’ll notice that the NorthwindDataService project is currently set to be hosted in the ASP.NET development server right now so that testing the Excel and Outlook clients is easy. However at this point you may opt to deploy this to IIS instead so that you don’t have to remember to start it up manually every time you want to test the SharePoint Workflow. And of course for deployment to production you’ll need to host it in IIS anyway. &lt;/p&gt;

&lt;p&gt;It gets slightly tricky if you want to host the data service in IIS on the same server as SharePoint because SharePoint takes over Port 80. So the easiest thing to do is to open IIS Manager and just create a new web site on Port 82 called NorthwindHost and then create a new application virtual directory called Northwind under that. By default, when you create a new web site it should also create a new Application Pool for you running under the identity NETWORK SERVICE. The identity you use here will need to have read and execute file permissions on the physical locations of any virtual directories you create as well as proper database permissions. &lt;/p&gt;

&lt;p&gt;It’s XCOPY deployment at that point. Just copy the Web.Config, Northwind.svc and the \bin directory over to the physical location of the Northwind virtual directory and you should be good to go.&amp;#160; You can do this in Visual Studio (if running as an administrator) just right-click on the NorthwindDataService project in the solution explorer and then select publish. Then enter http://localhost:82/Northwind/ (or whatever you named it) and it will build and publish the files there automatically. &lt;/p&gt;

&lt;p&gt;Note however, that before the WCF service will activate you have to install the WCF service handlers into IIS. These may not be installed automatically so in Windows 2008 check the Server Manager, scroll down to the Features Summary and select “Add Features”. Then expand the first node “.NET&amp;#160; 3.0 Features” and check WCF Activation. &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Remember if you change the location of the data service then you need to update the settings in the Excel and Outlook client (app.config file). &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating the SharePoint Workflow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you’re not doing this already, restart Visual Studio and &lt;strong&gt;Run as Administrator&lt;/strong&gt;. This is necessary so that you can deploy and debug your workflow. Next add a new project to the solution, File –&amp;gt; Add –&amp;gt; New Project. For this example we’re just going to create a simple SharePoint 2007 Sequential Workflow. (Note: You will need Visual Studio 2008 Professional and higher to get these templates.)&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA6_2.jpg"&gt;&lt;img title="SPOBA6" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="352" alt="SPOBA6" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA6_thumb.jpg" width="546" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;As I mentioned before the workflow will kick off when a new purchase order is added to the document library in order to parse the data in the document. So when the order is first added to the list it will have a status of &lt;strong&gt;New&lt;/strong&gt;. After it is parsed we will set the status to &lt;strong&gt;Processed&lt;/strong&gt;, which happens right away. Later, after the shipping department enters the shipped date in the Excel client and updates the Orders.ShippedDate field in the database, we need the workflow to wake back up and set the order status to &lt;strong&gt;Shipped&lt;/strong&gt;. For this example I’m going to build a delay into the workflow to check the database (via our data service) every so often. For testing it can be a couple minutes but once we deploy we can set it to every couple hours. Note that if you’re building more statuses or states into your own workflows you may want to take a look at the State Machine Workflow template instead. &lt;/p&gt;

&lt;p&gt;So the next step is to specify where your SharePoint site and document library resides, for development this is going to be http://&lt;em&gt;YourServerName. &lt;/em&gt;Once you specify the site you can then select the Orders document library in the Library dropdown. Leave “Automatically associate workflow?” checked so that Visual Studio can deploy the workflow to the site automatically for us. &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA8_2.jpg"&gt;&lt;img title="SPOBA8" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="273" alt="SPOBA8" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA8_thumb.jpg" width="345" border="0" /&gt;&lt;/a&gt; &lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA9_2.jpg"&gt;&lt;img title="SPOBA9" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="275" alt="SPOBA9" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA9_thumb.jpg" width="344" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;On the next page check off how you want to start the workflow. For this example we’ll select “When an item is created”. You can also check “Manually by users” which can be helpful when testing but it’s not necessary for our example. Note that you can change these settings later on the Workflow project -- from the Project menu select “SharePoint debug settings..”. You need to be running Visual Studio as an administrator to open these settings. &lt;strong&gt;You’ll need to do this if you’re going to run the Workflow in the &lt;/strong&gt;&lt;a href="http://code.msdn.microsoft.com/OBANorthwind"&gt;&lt;strong&gt;sample code&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; against your own SharePoint site.&amp;#160; &lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When the project is created it will automatically add a workflow called Workflow1 and open the designer which will display an event activity for onWorkflowActivated. An OnWorkflowActivated activity must be the first activity in a Windows SharePoint Services workflow so Visual Studio automatically sets one up for us. I renamed Workflow1 to ProcessOrder in the Solution Explorer (I like descriptive names ;-)) which means I’ll also need to update the values for the CorrelationToken.OwnerActivityName as well as the WorkflowProperties.Name to set them to ProcessOrder: &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA10_2.jpg"&gt;&lt;img title="SPOBA10" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="260" alt="SPOBA10" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA10_thumb.jpg" width="709" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now you can start laying out the design of the workflow. If you have used the WF designer before then this part should be familiar. Take a look at your toolbox and you’ll see the SharePoint specific activities listed under the Workflow 3.0 and 3.5 tabs. The design of the workflow for this example will be simple. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA7_4.jpg"&gt;&lt;img title="SPOBA7" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="562" alt="SPOBA7" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA7_thumb_1.jpg" width="536" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;There are three main blocks to the workflow that we’re going to build:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;First is the parsing of the order data in the document which is a standard code activity that you find in the Windows Workflow v3.0 tab on the toolbox. &lt;/li&gt;

  &lt;li&gt;The second block is a standard While loop that contains a delay activity. This piece will periodically query the database until the Order.ShipDate is updated in the database by the Excel client. &lt;/li&gt;

  &lt;li&gt;The third block will be an IfElse activity which will check the Order status and either write an informational message to the History list in the case the order shipped successfully, otherwise we create a Task and assign it to the administrator for further investigation. The LogToHistoryListActivity and the CreateTask items can be found in the SharePoint Workflow tab on the toolbox. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Before we start writing the workflow code, let’s create some constants that we can use to refer to the data service URI, our order statuses, and list column names (I just added a new Module called Constants.vb):&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Friend Module &lt;/span&gt;Constants
    &lt;span style="color: blue"&gt;Public Const &lt;/span&gt;OrderStatusColumn &lt;span style="color: blue"&gt;As String &lt;/span&gt;= &lt;span style="color: #a31515"&gt;&amp;quot;Order Status&amp;quot;
    &lt;/span&gt;&lt;span style="color: blue"&gt;Public Const &lt;/span&gt;OrderNumberColumn &lt;span style="color: blue"&gt;As String &lt;/span&gt;= &lt;span style="color: #a31515"&gt;&amp;quot;Order Number&amp;quot;
    &lt;/span&gt;&lt;span style="color: blue"&gt;Public Const &lt;/span&gt;ShippedDateColumn &lt;span style="color: blue"&gt;As String &lt;/span&gt;= &lt;span style="color: #a31515"&gt;&amp;quot;Shipped Date&amp;quot;
    &lt;/span&gt;&lt;span style="color: blue"&gt;Public Const &lt;/span&gt;SalesRepEmailColumn &lt;span style="color: blue"&gt;As String &lt;/span&gt;= &lt;span style="color: #a31515"&gt;&amp;quot;Sales Rep Email&amp;quot;

    &lt;/span&gt;&lt;span style="color: blue"&gt;Public Const &lt;/span&gt;NewStatus &lt;span style="color: blue"&gt;As String &lt;/span&gt;= &lt;span style="color: #a31515"&gt;&amp;quot;New&amp;quot;
    &lt;/span&gt;&lt;span style="color: blue"&gt;Public Const &lt;/span&gt;ShippedStatus &lt;span style="color: blue"&gt;As String &lt;/span&gt;= &lt;span style="color: #a31515"&gt;&amp;quot;Shipped&amp;quot;
    &lt;/span&gt;&lt;span style="color: blue"&gt;Public Const &lt;/span&gt;ProcessedStatus &lt;span style="color: blue"&gt;As String &lt;/span&gt;= &lt;span style="color: #a31515"&gt;&amp;quot;Processed&amp;quot;
    &lt;/span&gt;&lt;span style="color: blue"&gt;Public Const &lt;/span&gt;OnHoldStatus &lt;span style="color: blue"&gt;As String &lt;/span&gt;= &lt;span style="color: #a31515"&gt;&amp;quot;On Hold&amp;quot;
    &lt;/span&gt;&lt;span style="color: blue"&gt;Public Const &lt;/span&gt;CanceledStatus &lt;span style="color: blue"&gt;As String &lt;/span&gt;= &lt;span style="color: #a31515"&gt;&amp;quot;Canceled&amp;quot;

&lt;/span&gt;&lt;span style="color: green"&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;Public Const &lt;/span&gt;ServiceURL &lt;span style="color: blue"&gt;As String &lt;/span&gt;= &lt;span style="color: #a31515"&gt;&amp;quot;http://localhost:82/NorthwindService/Northwind.svc&amp;quot;
&lt;/span&gt;&lt;span style="color: blue"&gt;End Module&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Parsing the Order Document &lt;strong&gt;(CodeActivity parseOrder) &lt;/strong&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Workflow kicks off immediately after a purchase order document is checked into the document library. The first code activity out of the gate is parsing the order document’s customXML for the order data we need. I already &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/12/oba-part-3-storing-and-reading-data-in-word-documents.aspx"&gt;demonstrated a simple console application for extracting the order data from a Word document in Part 3&lt;/a&gt;. This code uses the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c6e744e5-36e9-45f5-8d8c-331df206e0d0&amp;amp;DisplayLang=en"&gt;Open XML SDK&lt;/a&gt; so you’ll need to download that and install it on your SharePoint server so that the assemblies are in the GAC. Then add an assembly reference to DocumentFormat.OpenXML. &lt;/p&gt;

&lt;p&gt;From that console application project I copied the DocumentOderData.vb, Extensions.vb code files and the OrderEntry.xsd into the workflow project. Module1.vb had a method called ParseOrderDocument which parsed the docx file and populated a DocumentOrderData class with the information. I took that code and created a new class called Shredder and modified the interface a bit so that we could pass it a Microsoft.Sharepoint.SPFile class instead: &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;DocumentFormat.OpenXml.Packaging
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #b96464"&gt;xmlns&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;urn:microsoft:examples:oba&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;

&lt;/span&gt;&lt;span style="color: blue"&gt;Public Class &lt;/span&gt;Shredder

    &lt;span style="color: blue"&gt;Public Function &lt;/span&gt;ParseOrderDocument(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;docFile &lt;span style="color: blue"&gt;As &lt;/span&gt;SPFile) &lt;span style="color: blue"&gt;As &lt;/span&gt;DocumentOrderData
        &lt;span style="color: blue"&gt;Using &lt;/span&gt;docStream = docFile.OpenBinaryStream
            &lt;span style="color: blue"&gt;Return &lt;/span&gt;ParseOrderDocument(WordprocessingDocument.Open(docStream, &lt;span style="color: blue"&gt;False&lt;/span&gt;))
        &lt;span style="color: blue"&gt;End Using
    End Function

&lt;/span&gt;&lt;span style="color: gray"&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;Public Function &lt;/span&gt;ParseOrderDocument(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;wordDoc &lt;span style="color: blue"&gt;As &lt;/span&gt;WordprocessingDocument) &lt;span style="color: blue"&gt;As &lt;/span&gt;DocumentOrderData&lt;br /&gt;...&lt;/pre&gt;

&lt;p&gt;We also had a means for adding this data to the database via a method called AddNewOrder. The only change we need here is to create a unique OrderNumber string, add it to the Order entity, and return it to the workflow so we can also set it on the list item in SharePoint. You can decide how you want to generate unique order numbers, whether you want them to be GIUDs or timestamps or some other random number. I like using a combination of the CustomerID and the current date&amp;amp;time so that it’s human readable.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;orderNum = Replace(Replace(Replace(cust.CustomerID &amp;amp; Now.ToString(), &lt;span style="color: #a31515"&gt;&amp;quot;/&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;), &lt;span style="color: #a31515"&gt;&amp;quot;:&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;), &lt;span style="color: #a31515"&gt;&amp;quot; &amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;)&lt;/pre&gt;

&lt;p&gt;This will work as long as there aren’t two orders for the same customer submitted within the same second so depending on your actual scenario you may opt for a different strategy :-). So this AddNewOrder code I placed into a class called OrderManager which also encapsulates all calls to the data service. Speaking of our data service, we’ll need to add a Service Reference to the workflow project called NorthwindService (right-click on the workflow project and select Add Service Reference) which will add the database entity types to our project. &lt;/p&gt;

&lt;p&gt;Now drop a CodeActivity onto the Workflow designer and in the properties window name it parseOrder. Then right-click on it in the designer and select Generate Handlers to automatically generate the parseOrder_ExecuteCode handler. If the order data is extracted and added to the database successfully then an order number is assigned and the status is set to Processed. If the document does not contain the &amp;lt;OrderEntry&amp;gt; CustomXML then the status will be set to Canceled. If there is a problem adding the data to the database then the status is set to On Hold. (Notice that this code also uses the Application.Log to write messages to the Event Log which you can &lt;a href="http://msdn.microsoft.com/en-us/library/07347hdt.aspx"&gt;see how to set up here&lt;/a&gt;.)&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Public Class &lt;/span&gt;ProcessOrder
    &lt;span style="color: blue"&gt;Inherits &lt;/span&gt;SequentialWorkflowActivity

    &lt;span style="color: blue"&gt;Public &lt;/span&gt;workflowProperties &lt;span style="color: blue"&gt;As New &lt;/span&gt;SPWorkflowActivationProperties
    &lt;span style="color: blue"&gt;Public Sub New&lt;/span&gt;()
        &lt;span style="color: blue"&gt;MyBase&lt;/span&gt;.New()
        InitializeComponent()
    &lt;span style="color: blue"&gt;End Sub

    Private Sub &lt;/span&gt;parseOrder_ExecuteCode(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;sender &lt;span style="color: blue"&gt;As &lt;/span&gt;System.Object, _
                                       &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;e &lt;span style="color: blue"&gt;As &lt;/span&gt;System.EventArgs)
        &lt;span style="color: green"&gt;'This method is executed once the purchase order is uploaded 
        ' and checked into the document library 
        &lt;/span&gt;&lt;span style="color: blue"&gt;Try
            Dim &lt;/span&gt;orderNumber &lt;span style="color: blue"&gt;As String &lt;/span&gt;= &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot;
            &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;shredder &lt;span style="color: blue"&gt;As New &lt;/span&gt;Shredder

            &lt;span style="color: green"&gt;'Valid OrderStatus: New, Processed, Shipped, Cancelled, On Hold
            ' (See Constants.vb for column and status strings)
            &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;status = workflowProperties.Item(OrderStatusColumn).ToString()

            &lt;span style="color: blue"&gt;If &lt;/span&gt;status = NewStatus &lt;span style="color: blue"&gt;Then
                &lt;/span&gt;&lt;span style="color: green"&gt;'Get order data out of the document
                &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;docData = shredder.ParseOrderDocument(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.workflowProperties.Item.File)

                &lt;span style="color: blue"&gt;If &lt;/span&gt;docData &lt;span style="color: blue"&gt;IsNot Nothing Then
                    Dim &lt;/span&gt;manager &lt;span style="color: blue"&gt;As New &lt;/span&gt;OrderManager
                    &lt;span style="color: blue"&gt;Dim &lt;/span&gt;employeeEmail = workflowProperties.Item(SalesRepEmailColumn).ToString()

                    &lt;span style="color: green"&gt;'Add order data to the DB (through the service) and return the order number.
                    &lt;/span&gt;orderNumber = manager.AddNewOrder(docData, employeeEmail)

                    &lt;span style="color: blue"&gt;If &lt;/span&gt;orderNumber &amp;lt;&amp;gt; &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;Then
                        &lt;/span&gt;status = ProcessedStatus
                        &lt;span style="color: blue"&gt;My&lt;/span&gt;.Application.Log.WriteEntry( _
                            &lt;span style="color: blue"&gt;String&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;Order {0} added to database successfully.&amp;quot;&lt;/span&gt;, _
                                          orderNumber), TraceEventType.Information)
                    &lt;span style="color: blue"&gt;Else
                        &lt;/span&gt;status = OnHoldStatus
                        &lt;span style="color: blue"&gt;My&lt;/span&gt;.Application.Log.WriteEntry( _
                            &lt;span style="color: blue"&gt;String&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;Order could not be added to database for {0}.&amp;quot;&lt;/span&gt;, _
                                          &lt;span style="color: blue"&gt;Me&lt;/span&gt;.workflowProperties.Item.Name), TraceEventType.Error)
                    &lt;span style="color: blue"&gt;End If
                Else
                    &lt;/span&gt;status = CanceledStatus
                    &lt;span style="color: blue"&gt;My&lt;/span&gt;.Application.Log.WriteEntry( _
                        &lt;span style="color: blue"&gt;String&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;Invalid purchase order submitted for {0}&amp;quot;&lt;/span&gt;, _
                                      &lt;span style="color: blue"&gt;Me&lt;/span&gt;.workflowProperties.Item.Name), TraceEventType.Error)
                &lt;span style="color: blue"&gt;End If
            End If

            If &lt;/span&gt;status &amp;lt;&amp;gt; &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;Then
                Me&lt;/span&gt;.workflowProperties.Item(OrderStatusColumn) = status
                &lt;span style="color: blue"&gt;If &lt;/span&gt;orderNumber.Length() &amp;gt; 0 &lt;span style="color: blue"&gt;Then
                    Me&lt;/span&gt;.workflowProperties.Item(OrderNumberColumn) = orderNumber
                &lt;span style="color: blue"&gt;End If
                Me&lt;/span&gt;.workflowProperties.Item.Update()
            &lt;span style="color: blue"&gt;End If

        Catch &lt;/span&gt;ex &lt;span style="color: blue"&gt;As &lt;/span&gt;Exception
            &lt;span style="color: blue"&gt;My&lt;/span&gt;.Application.Log.WriteException(ex)
        &lt;span style="color: blue"&gt;End Try

    End Sub&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Now that the order is in the database, you can open &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/03/08/oba-part-4-building-an-excel-client-against-lob-data.aspx"&gt;the Excel client we wrote in part 4&lt;/a&gt; and enter a ShippedDate and click save to update the order. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Querying the Database Periodically (&lt;strong&gt;WhileActivity waitForProcessed&lt;/strong&gt;)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next we need a WhileActivity so that we can check the database to see if the ShippedDate has been updated. Drag a standard While activity from the toolbox under the parseOrder and name it waitForProcessed in the properties window. Right-click on the designer and select View Code and write the following method:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;    Private Sub &lt;/span&gt;orderProcessed(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;sender &lt;span style="color: blue"&gt;As &lt;/span&gt;System.Object, &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;e &lt;span style="color: blue"&gt;As &lt;/span&gt;ConditionalEventArgs)
      &lt;span style="color: blue"&gt;Try
            Dim &lt;/span&gt;status = &lt;span style="color: blue"&gt;Me&lt;/span&gt;.workflowProperties.Item(OrderStatusColumn).ToString()
            &lt;span style="color: blue"&gt;Dim &lt;/span&gt;orderNumber = &lt;span style="color: blue"&gt;Me&lt;/span&gt;.workflowProperties.Item(Constants.OrderNumberColumn).ToString()

            &lt;span style="color: blue"&gt;If &lt;/span&gt;status &amp;lt;&amp;gt; ProcessedStatus &lt;span style="color: blue"&gt;Then
                &lt;/span&gt;&lt;span style="color: green"&gt;'End while branch and go to next step in sequence if status is:
                '  Canceled = invalid purchase order (no &amp;lt;OrderEntry&amp;gt; CustomXML found)
                '  On Hold = Could not add data to database (see error log for details)
                &lt;/span&gt;e.Result = &lt;span style="color: blue"&gt;False
            Else
                &lt;/span&gt;&lt;span style="color: green"&gt;'Get order from DB
                &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;manager &lt;span style="color: blue"&gt;As New &lt;/span&gt;OrderManager
                &lt;span style="color: blue"&gt;Dim &lt;/span&gt;processedOrder = manager.GetOrder(orderNumber)

                &lt;span style="color: green"&gt;'If order was shipped (ShippedDate not NULL) then set Order Status to Shipped.
                &lt;/span&gt;&lt;span style="color: blue"&gt;If &lt;/span&gt;processedOrder &lt;span style="color: blue"&gt;IsNot Nothing Then
                    If &lt;/span&gt;processedOrder.ShippedDate &lt;span style="color: blue"&gt;IsNot Nothing AndAlso &lt;/span&gt;_
                       processedOrder.ShippedDate.HasValue &lt;span style="color: blue"&gt;Then
                        My&lt;/span&gt;.Application.Log.WriteEntry( _
                            &lt;span style="color: blue"&gt;String&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;Order {0} has shipped as of {1}&amp;quot;&lt;/span&gt;, _
                                          orderNumber, Now()), TraceEventType.Information)

                        &lt;span style="color: blue"&gt;Me&lt;/span&gt;.workflowProperties.Item(OrderStatusColumn) = ShippedStatus
                        &lt;span style="color: blue"&gt;Me&lt;/span&gt;.workflowProperties.Item(ShippedDateColumn) = processedOrder.ShippedDate
                        &lt;span style="color: blue"&gt;Me&lt;/span&gt;.workflowProperties.Item.Update()
                        &lt;span style="color: green"&gt;'end while branch and go to next step in sequence
                        &lt;/span&gt;e.Result = &lt;span style="color: blue"&gt;False
                    Else
                        My&lt;/span&gt;.Application.Log.WriteEntry( _
                            &lt;span style="color: blue"&gt;String&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;Order {0} has not shipped as of {1}&amp;quot;&lt;/span&gt;, _
                                          orderNumber, Now()), TraceEventType.Warning)
                        &lt;span style="color: green"&gt;'keep workflow running until shipped or canceled
                        &lt;/span&gt;e.Result = &lt;span style="color: blue"&gt;True
                    End If
                Else
                    My&lt;/span&gt;.Application.Log.WriteEntry( _
                        &lt;span style="color: blue"&gt;String&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;Order {0} has been deleted from the database&amp;quot;&lt;/span&gt;, _
                                      orderNumber, Now()), TraceEventType.Error)&lt;br /&gt;
                    &lt;span style="color: blue"&gt;Me&lt;/span&gt;.workflowProperties.Item(OrderStatusColumn) = CanceledStatus
                    &lt;span style="color: blue"&gt;Me&lt;/span&gt;.workflowProperties.Item.Update()
                    &lt;span style="color: green"&gt;'end while branch and go to next step in sequence
                    &lt;/span&gt;e.Result = &lt;span style="color: blue"&gt;False
                End If
            End If

        Catch &lt;/span&gt;ex &lt;span style="color: blue"&gt;As &lt;/span&gt;Exception
            &lt;span style="color: blue"&gt;My&lt;/span&gt;.Application.Log.WriteException(ex)
        &lt;span style="color: blue"&gt;End Try

    End Sub&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Notice in this code we’re referring to a method on the OrderManager called GetOrder which simply queries the Order entity from the database via the data service using LINQ:&lt;/p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;OBADemoWorkflow.NorthwindServiceReference

&lt;span style="color: blue"&gt;Public Class &lt;/span&gt;OrderManager
    &lt;span style="color: blue"&gt;Private &lt;/span&gt;ctx &lt;span style="color: blue"&gt;As New &lt;/span&gt;NorthwindEntities(&lt;span style="color: blue"&gt;New &lt;/span&gt;Uri(Constants.ServiceURL))&lt;br /&gt;
&lt;span style="color: blue"&gt;    Public Function &lt;/span&gt;AddNewOrder(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;docData &lt;span style="color: blue"&gt;As &lt;/span&gt;DocumentOrderData, _&lt;br /&gt;                                &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;employeeEmail &lt;span style="color: blue"&gt;As String&lt;/span&gt;) &lt;span style="color: blue"&gt;As String...

&lt;/span&gt;&lt;span style="color: gray"&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;Public Function &lt;/span&gt;GetOrder(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;orderNumber &lt;span style="color: blue"&gt;As String&lt;/span&gt;) &lt;span style="color: blue"&gt;As &lt;/span&gt;Order
        &lt;span style="color: blue"&gt;Try
            Dim &lt;/span&gt;theOrder = (&lt;span style="color: blue"&gt;From &lt;/span&gt;o &lt;span style="color: blue"&gt;In &lt;/span&gt;ctx.Orders _
                            &lt;span style="color: blue"&gt;Where &lt;/span&gt;o.OrderNumber = orderNumber).FirstOrDefault()

            &lt;span style="color: blue"&gt;Return &lt;/span&gt;theOrder

        &lt;span style="color: blue"&gt;Catch &lt;/span&gt;ex &lt;span style="color: blue"&gt;As &lt;/span&gt;Exception
            &lt;span style="color: blue"&gt;My&lt;/span&gt;.Application.Log.WriteException(ex)
            &lt;span style="color: blue"&gt;Return Nothing
        End Try
    End Function
End Class&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA11_2.jpg"&gt;&lt;img title="SPOBA11" style="border-right: 0px; border-top: 0px; display: inline; margin: 0px 10px 0px 0px; border-left: 0px; border-bottom: 0px" height="166" alt="SPOBA11" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA11_thumb.jpg" width="233" align="left" border="0" /&gt;&lt;/a&gt; Now you can go back to the designer and set the Condition on the waitForProcessed WhileActivity to the orderProcessed method. Set the Condition to a Code Condition and the dropdown will contain only those methods that have the right signature, i.e. have a ConditionalEventArgs parameter. The orderProcessed method will set the e.Result = True only if the order is in the Processed state, is still in the database, and its ShippedDate is still NULL. This means that the While activity will continue to run. &lt;/p&gt;

&lt;p&gt;Because the shipping department most likely will not ship the order out the door the second the order is entered into the database (&amp;lt;g&amp;gt;), we need a way for our workflow to delay and check periodically. Depending on your business you may want to check hourly or even daily. For testing you probably want to check every minute or two. This is where the DelayActivity comes in. Drag a standard Delay activity onto the designer inside the While Activity and set the Timeout Duration in the properties window to 3 minutes or so. &lt;/p&gt;

&lt;p&gt;Before we go on I want to mention that there were known issues with the Delay activities not firing correctly in SharePoint that are addressed by this KB Article: &lt;a title="http://support.microsoft.com/kb/953630/" href="http://support.microsoft.com/kb/953630/"&gt;http://support.microsoft.com/kb/953630/&lt;/a&gt;. The SharePoint timer service (OWSTIMER.exe) is set to only wake up every 5 minutes, so you probably want to set that to a shorter interval in your testing environment otherwise you’ll have to wait at least 5 minutes no matter how short you set your Delay activity. Another other issue I noticed was sometimes on rebuild &amp;amp; redeployment I needed to restart the timer service manually from an admin command prompt:&lt;/p&gt;

&lt;p&gt;&amp;gt;Net Stop SPTimerV3
  &lt;br /&gt;&amp;gt;iisreset

  &lt;br /&gt;&amp;gt;Net Start SPTimerV3&lt;/p&gt;

&lt;p&gt;Also there is an issue with debugging delays. I couldn’t just press F5 to debug the workflow after the delay. Up until that point I debugged just fine (which is where almost all our code is in this example) but if I wanted to see the rest of the code execute after the delay then I needed to attach to the OWSTIMER.exe process (while you’re debugging, on the main menu select Tools –&amp;gt; Attach to Process). This is also one of&amp;#160; the reasons why I enabled the Application.Log to send messages to the Event Log. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Wrapping Up the Workflow (History Logging and Creating Tasks)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The last piece of the workflow is simple, if the order is shipped we’ll just log a message to the workflow history list otherwise we’ll create a task for the administrator to investigate. Drop an IfElse activity under the While activity set and name it checkIfShipped. Then name the first branch ifShipped and the second branch elseNotShipped. In the ifShipped branch drop a LogToHistoryListActivity which is found in the SharePoint Workflow tab on the Toolbox. In the elseNotShipped drop a CreateTask activity. On the properties window for the CreateTask create a new field binding for both the TaskID and TaskProperties and enter a correlationToken with the parent activity set to ProcessOrder (the workflow). &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA12_2.jpg"&gt;&lt;img title="SPOBA12" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="297" alt="SPOBA12" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/SPOBA12_thumb.jpg" width="709" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Then right-click on both the CreateTask and LogToHistoryActivity and select Generate Handlers in order to generate the method stubs for each of them. We’ll also need a method called isOrderShipped with the same signature as the orderProcessed method above to be able to set it as the Code Condition of the ifShipped branch. We need to check the workflowProperties.Item for the order status and set the e.Result = True if the status is Shipped. &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;isOrderShipped(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;sender &lt;span style="color: blue"&gt;As Object&lt;/span&gt;, &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;e &lt;span style="color: blue"&gt;As &lt;/span&gt;ConditionalEventArgs)
&lt;span style="color: green"&gt;    'Returns True if Order Status equals Shipped
    &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;status = &lt;span style="color: blue"&gt;Me&lt;/span&gt;.workflowProperties.Item(OrderStatusColumn).ToString()
    e.Result = (status = ShippedStatus)
&lt;span style="color: blue"&gt;End Sub

Private Sub &lt;/span&gt;createTask1_MethodInvoking(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;sender &lt;span style="color: blue"&gt;As &lt;/span&gt;System.Object, &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;e &lt;span style="color: blue"&gt;As &lt;/span&gt;System.EventArgs)
    &lt;span style="color: blue"&gt;Try
        &lt;/span&gt;&lt;span style="color: green"&gt;'This will execute if the workflow is ending but the Order Status 
        ' is not Shipped (i.e. Canceled or On Hold). 
        ' This code creates a workflow task item so the AssignedTo can investigate.
        &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;status = &lt;span style="color: blue"&gt;Me&lt;/span&gt;.workflowProperties.Item(OrderStatusColumn).ToString()
        &lt;span style="color: blue"&gt;Dim &lt;/span&gt;name = &lt;span style="color: blue"&gt;Me&lt;/span&gt;.workflowProperties.Item.Name

        createTask1_TaskId1 = Guid.NewGuid()
        createTask1_TaskProperties1.AssignedTo = &lt;span style="color: #a31515"&gt;&amp;quot;obavm09\wssdeveloper&amp;quot;
        &lt;/span&gt;createTask1_TaskProperties1.Title = &lt;span style="color: blue"&gt;String&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;Problem with order {0}&amp;quot;&lt;/span&gt;, name)
        createTask1_TaskProperties1.Description = &lt;span style="color: blue"&gt;String&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;Order {0} as of {1}&amp;quot;&lt;/span&gt;, status, Now)
    &lt;span style="color: blue"&gt;Catch &lt;/span&gt;ex &lt;span style="color: blue"&gt;As &lt;/span&gt;Exception
        &lt;span style="color: blue"&gt;My&lt;/span&gt;.Application.Log.WriteException(ex)
    &lt;span style="color: blue"&gt;End Try
End Sub

Private Sub &lt;/span&gt;logToHistoryListActivity1_MethodInvoking(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;sender &lt;span style="color: blue"&gt;As &lt;/span&gt;System.Object, _&lt;br /&gt;                                                     &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;e &lt;span style="color: blue"&gt;As &lt;/span&gt;System.EventArgs)
    logToHistoryListActivity1.HistoryOutcome = &lt;span style="color: #a31515"&gt;&amp;quot;Order has been shipped.&amp;quot;
&lt;/span&gt;&lt;span style="color: blue"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;Testing the Workflow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Visual Studio (still running as Administrator) Rebuild the solution. Then right-click on the OBADemoWorkflow project and select Deploy from the context menu. Now we can head over to the document library and upload some purchase orders. I used the one we created previously in &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/12/oba-part-3-storing-and-reading-data-in-word-documents.aspx"&gt;Part 3&lt;/a&gt; with ALFKI as the CustomerID. Go to the Orders document library, click Upload, Browse for the purchase order and click OK. Then fill out the required field Sales Rep Email (this is the Employee.EmailAddress field we added to the database in &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/03/oba-part-1-exposing-line-of-business-data.aspx"&gt;Part 1&lt;/a&gt;). Once you click “Check In” the workflow will kick off. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/OrderWorkflow1_2.jpg"&gt;&lt;img title="OrderWorkflow1" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="352" alt="OrderWorkflow1" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/OrderWorkflow1_thumb.jpg" width="639" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The Order status is first set to “New”….&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/OrderWorkflow2_2.jpg"&gt;&lt;img title="OrderWorkflow2" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="352" alt="OrderWorkflow2" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/OrderWorkflow2_thumb.jpg" width="663" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;But if you quickly refresh the list you will see that the Order Status and Order Number change as the order is processed and entered into the database. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/OrderWorkflow3_2.jpg"&gt;&lt;img title="OrderWorkflow3" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="352" alt="OrderWorkflow3" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/OrderWorkflow3_thumb.jpg" width="658" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now the workflow is in its delay activity waiting for us to update the Order.ShippedDate. Open up the Excel client and enter something in the ShippedDate field and save the sheet (or manually modify the database). The next time the SharePoint timer runs it will waken our delay which will check the database again and set the status appropriately.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/OrderWorkflow4_2.jpg"&gt;&lt;img title="OrderWorkflow4" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="352" alt="OrderWorkflow4" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildingtheSharePointWorkFlow_D714/OrderWorkflow4_thumb.jpg" width="661" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;If you select the OBADemoWorkflow status (the last column in the view which is added automatically for us when we deploy) then you can see the status message in the Workflow History list. To see a task get created you can perform the same process but instead of updating the ShippedDate, delete the Order from the database (or delete the OrderNumber) and the workflow will set the status to Canceled and you will see a task in the list instead. And remember in testing we set the delay to a few minutes but in production Northwind Traders will be good with a 12 hour delay (gourmet foods don’t ship that quickly ;-)). &lt;/p&gt;

&lt;p&gt;I’ve added this workflow to the &lt;a href="http://code.msdn.com/obanorthwind"&gt;sample code we’ve been building up on Code Gallery&lt;/a&gt; so have a look. I hope this real(er)-world, componentized sample has given you a good introduction into OBA and some of the awesome VSTO features of Visual Studio 2008. &lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9561302" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Article/default.aspx">Article</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Office/default.aspx">Office</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Workflow/default.aspx">Workflow</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/ADO.NET+Data+Services/default.aspx">ADO.NET Data Services</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VSTO/default.aspx">VSTO</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/SharePoint/default.aspx">SharePoint</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/OBA/default.aspx">OBA</category></item><item><title>OBA Part 4 - Building an Excel Client against LOB Data</title><link>http://blogs.msdn.com/bethmassi/archive/2009/03/08/oba-part-4-building-an-excel-client-against-lob-data.aspx</link><pubDate>Mon, 09 Mar 2009 01:45:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9466700</guid><dc:creator>Beth Massi</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9466700.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9466700</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9466700</wfw:comment><description>&lt;p&gt;In my last few app building posts we've been building a simple Office Business Application (OBA) for the new Northwind Traders. If you missed them:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/03/oba-part-1-exposing-line-of-business-data.aspx"&gt;OBA Part 1 - Exposing Line-of-Business Data&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/07/oba-part-2-building-and-outlook-client-against-lob-data.aspx"&gt;OBA Part 2 - Building and Outlook Client against LOB Data&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/12/oba-part-3-storing-and-reading-data-in-word-documents.aspx"&gt;OBA Part 3 - Storing and Reading Data in Word Documents&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;(In the &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/12/oba-part-3-storing-and-reading-data-in-word-documents.aspx" target="_blank"&gt;last post&lt;/a&gt; on OBA I mentioned we would build out the &lt;a href="http://msdn.microsoft.com/en-us/library/cc936628.aspx" target="_blank"&gt;SharePoint Workflow&lt;/a&gt; next but I realized that it's important to see how the Excel client works before we write the workflow, so that will be the next post.)&lt;/p&gt;  &lt;p&gt;In this post I want to focus on how we can build an Excel client for our shipping department. This will be a customized Excel spreadsheet that lists the orders that need to be shipped and allows users to enter the ship dates and save them back to the database. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildinganExcelClientagainstLOBD_E5CD/OBAExcel1_4.jpg"&gt;&lt;img height="179" alt="OBAExcel1" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildinganExcelClientagainstLOBD_E5CD/OBAExcel1_thumb_1.jpg" width="524" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;We'll also generate a pivot table and chart so that we can visualize the percentages of cities that we're shipping our products. This is one of the key advantages of building an Excel client. Not only does it lend itself well for editing tabular data, it also makes it very easy to provide additional analysis of that data. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;The Excel Document Customization&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;I've been building upon the the Visual Studio Solution that we started in the first post on OBA when we built the data service. So just add a new project to the solution (File -&amp;gt; &lt;strong&gt;Add&lt;/strong&gt; -&amp;gt; New Project) and select Office 2007 Excel Workbook which is available in Visual Studio 2008 Professional and higher:&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildinganExcelClientagainstLOBD_E5CD/OBAExcelClient1_4.jpg"&gt;&lt;img height="352" alt="OBAExcelClient1" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildinganExcelClientagainstLOBD_E5CD/OBAExcelClient1_thumb_1.jpg" width="702" border="0" /&gt;&lt;/a&gt;&amp;#160; &lt;/p&gt;  &lt;p&gt;Since we're building a document customization and not an Add-In this means that our code will only run on the specific document as opposed to running in the Excel application over any document that is opened. After we add the project we're asked if we want to import an existing Excel workbook or create a new one. For this example we'll want to create a new one named the same name as our project, NorthwindClientExcel.xlsx. After we specify this, our project is created and the Excel designer opens. &lt;/p&gt;  &lt;p&gt;Next step is to add the data service reference just like we did for the Outlook Add-In. Right-click on the project, select Add Service Reference. Click the Discover button and it should find our ADO.NET data service in the solution called NorthwindDataService. Name the service reference NorthwindService. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Data Binding in Excel&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Now that we have our service reference we can retrieve the list of Order objects that have not been shipped yet and display them in the first sheet of our workbook. But we'll also want to show the Order Details to the shipping department and display the Quantity and Product that should be shipped. We'll do this using an Excel &lt;a href="http://msdn.microsoft.com/en-us/library/7we49he1.aspx" target="_blank"&gt;Action Pane&lt;/a&gt; by setting up a master-detail view of the data. So as the user scrolls through the Order rows, the Action Pane will display the Order Details. The user only needs to make changes to the Order rows itself so this design will work well. &lt;/p&gt;  &lt;p&gt;The magic control we use in Excel to bind data to rows is called the &lt;a href="http://msdn.microsoft.com/en-us/library/2ttzcbhb.aspx" target="_blank"&gt;ListObject&lt;/a&gt;. This object can easily bind to a Winforms BindingSource just like any other Winforms control. So to set up our data source so we can bind to a BindingSource we'll want a BindingList(Of Order) so that list change notifications are communicated to the UI. We'll also need to augment the Order partial class on the client so that property change notifications are also sent. &lt;/p&gt;  &lt;p&gt;So first create a new class named Order and place it in the same Namespace as the NorthwindService service reference we just added. This is where the client proxy objects are generated for us so in order to extend these classes with our own code we just need to get it into the same Namespace. (Here's a Visual Basic tip, you know you've got it right if you see the Order properties and methods in the Declarations drop down above the editor for the Order class.) We need to fire a change notification on all of the properties of our Order so I've placed code to do this in all the xxxChanged() partial methods like so :&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;NorthwindExcelClient.NorthwindService
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.ComponentModel

&lt;span style="color: blue"&gt;Namespace &lt;/span&gt;NorthwindService

    &lt;span style="color: blue"&gt;Partial Public Class &lt;/span&gt;Order
        &lt;span style="color: blue"&gt;Implements &lt;/span&gt;INotifyPropertyChanged

        &lt;span style="color: blue"&gt;Public Event &lt;/span&gt;PropertyChanged(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;sender &lt;span style="color: blue"&gt;As Object&lt;/span&gt;, _
                                     &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;e &lt;span style="color: blue"&gt;As &lt;/span&gt;PropertyChangedEventArgs) _
                                     &lt;span style="color: blue"&gt;Implements &lt;/span&gt;INotifyPropertyChanged.PropertyChanged

        &lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;FirePropertyChanged(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;propertyName &lt;span style="color: blue"&gt;As String&lt;/span&gt;)
            &lt;span style="color: blue"&gt;If &lt;/span&gt;propertyName &amp;lt;&amp;gt; &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;Then
                RaiseEvent &lt;/span&gt;PropertyChanged(&lt;span style="color: blue"&gt;Me&lt;/span&gt;, &lt;span style="color: blue"&gt;New &lt;/span&gt;PropertyChangedEventArgs(propertyName))
            &lt;span style="color: blue"&gt;End If
        End Sub

        Private Sub &lt;/span&gt;OnShippedDateChanged()
            FirePropertyChanged(&lt;span style="color: #a31515"&gt;&amp;quot;ShippedDate&amp;quot;&lt;/span&gt;)
        &lt;span style="color: blue"&gt;End Sub

        Private Sub &lt;/span&gt;OnOrderDateChanged()
            FirePropertyChanged(&lt;span style="color: #a31515"&gt;&amp;quot;OrderDate&amp;quot;&lt;/span&gt;)
        &lt;span style="color: blue"&gt;End Sub

        &lt;/span&gt;&lt;span style="color: green"&gt;'FirePropertyChanged is called from all xxxChanged() partial methods.
        ' I excluded the rest of the code here for clarity....
.&lt;br /&gt;.&lt;br /&gt;.&lt;/span&gt;&lt;span style="color: green"&gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;    End Class&lt;br /&gt;End Namespace&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Next we need to create a BindingList(Of Order). I'm going to create a class called MyOrdersList that inherits from this which will also encapsulate the calls to the ADO.NET Data Service. MyOrdersList will use the data service context on the client (NorthwindService in our case) to retrieve and update the Orders. We don't want to allow adds or deletes in this application because orders are going through a workflow and our shipping department is only updating the information on an order, specifically the ShippedDate. So we'll need to override AddNewCore and RemoveItem to prevent this. We'll also override the OnListChanged so that we can tell the data service context to mark the Order entity as updated. &lt;/p&gt;

&lt;p&gt;We also need a couple housekeeping fields for saving and for exposing a HasChanges property. The interesting code to notice here is that we're specifying a MergeOption on the data service client to OverwriteChanges after we save as opposed to the default AppendOnly. This means that after we save our changes it will refresh the existing Order entity instances with changes from the database. &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;NorthwindExcelClient.NorthwindService
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.ComponentModel

&lt;span style="color: blue"&gt;Public Class &lt;/span&gt;MyOrderList
    &lt;span style="color: blue"&gt;Inherits &lt;/span&gt;BindingList(&lt;span style="color: blue"&gt;Of &lt;/span&gt;Order)

    &lt;span style="color: blue"&gt;Private &lt;/span&gt;DataServiceContext &lt;span style="color: blue"&gt;As New &lt;/span&gt;NorthwindEntities(&lt;span style="color: blue"&gt;New &lt;/span&gt;Uri(&lt;span style="color: blue"&gt;My&lt;/span&gt;.Settings.ServiceURI))
    &lt;span style="color: blue"&gt;Private &lt;/span&gt;_hasChanges &lt;span style="color: blue"&gt;As Boolean
    Private &lt;/span&gt;_isSaving &lt;span style="color: blue"&gt;As Boolean

    Public ReadOnly Property &lt;/span&gt;HasChanges() &lt;span style="color: blue"&gt;As Boolean
        Get
            Return &lt;/span&gt;_hasChanges
        &lt;span style="color: blue"&gt;End Get
    End Property

    Sub New&lt;/span&gt;()
        &lt;span style="color: blue"&gt;MyBase&lt;/span&gt;.New()
        &lt;span style="color: blue"&gt;Me&lt;/span&gt;.DataServiceContext.MergeOption = Services.Client.MergeOption.OverwriteChanges
    &lt;span style="color: blue"&gt;End Sub

    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' Do not allow adds.
    ''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
    &lt;/span&gt;&lt;span style="color: blue"&gt;Protected Overrides Function &lt;/span&gt;AddNewCore() &lt;span style="color: blue"&gt;As Object
        Throw New &lt;/span&gt;NotSupportedException(&lt;span style="color: #a31515"&gt;&amp;quot;You cannot add items to the list.&amp;quot;&lt;/span&gt;)
        &lt;span style="color: blue"&gt;Return Nothing
    End Function
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' Do not allow deletes.
    ''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;index&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
    &lt;/span&gt;&lt;span style="color: blue"&gt;Protected Overrides Sub &lt;/span&gt;RemoveItem(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;index &lt;span style="color: blue"&gt;As Integer&lt;/span&gt;)
        &lt;span style="color: blue"&gt;Throw New &lt;/span&gt;NotSupportedException(&lt;span style="color: #a31515"&gt;&amp;quot;You cannot remove items from the list.&amp;quot;&lt;/span&gt;)
    &lt;span style="color: blue"&gt;End Sub
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' When a property is updated on an order, then we need to
    ''' tell the data services client to mark it as updated.
    ''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;e&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
    &lt;/span&gt;&lt;span style="color: blue"&gt;Protected Overrides Sub &lt;/span&gt;OnListChanged(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;e &lt;span style="color: blue"&gt;As &lt;/span&gt;System.ComponentModel.ListChangedEventArgs)
        &lt;span style="color: blue"&gt;If Not &lt;/span&gt;_isSaving &lt;span style="color: blue"&gt;Then
            &lt;/span&gt;&lt;span style="color: green"&gt;'The Order partial class is implementing INotifyPropertyChanged so this will work
            &lt;/span&gt;&lt;span style="color: blue"&gt;If &lt;/span&gt;e.ListChangedType = ListChangedType.ItemChanged &lt;span style="color: blue"&gt;Then
                Me&lt;/span&gt;.DataServiceContext.UpdateObject(&lt;span style="color: blue"&gt;Me&lt;/span&gt;(e.NewIndex))
                _hasChanges = &lt;span style="color: blue"&gt;True
            End If
            MyBase&lt;/span&gt;.OnListChanged(e)
        &lt;span style="color: blue"&gt;End If
    End Sub&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Before we get into the code that will retrieve and save the orders, let's bind this to a ListObject and get it onto our Excel worksheet. Since we're going to have to interact with the list of orders from our Sheet1 as well as the &lt;a href="http://msdn.microsoft.com/en-us/library/7we49he1.aspx" target="_blank"&gt;Action Pane&lt;/a&gt; displaying the details, I'm going to create a property on the Workbook itself that exposes the MyOrdersList. Double-click on the ThisWorkbook in the project and switch to the Code view:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Public Class &lt;/span&gt;ThisWorkbook

    &lt;span style="color: green"&gt;'This is the data source we'll be working with on the Sheet and Action Pane.
    ' This class communicates with the ADO.NET Data Service
    &lt;/span&gt;&lt;span style="color: blue"&gt;Private &lt;/span&gt;_orderList &lt;span style="color: blue"&gt;As &lt;/span&gt;MyOrderList
    &lt;span style="color: blue"&gt;Public ReadOnly Property &lt;/span&gt;OrderList() &lt;span style="color: blue"&gt;As &lt;/span&gt;MyOrderList
        &lt;span style="color: blue"&gt;Get
            If &lt;/span&gt;_orderList &lt;span style="color: blue"&gt;Is Nothing Then
                &lt;/span&gt;_orderList = &lt;span style="color: blue"&gt;New &lt;/span&gt;MyOrderList()
            &lt;span style="color: blue"&gt;End If
            Return &lt;/span&gt;_orderList
        &lt;span style="color: blue"&gt;End Get
    End Property&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Now build the project and open the Data Sources window.&amp;#160; Add a new Object Data Source and select MyOrderList then Finish. Drag the MyOrderList onto the designer for Sheet1, just drop it into the first cell, and it will generate all the columns for every property on the Order. You can also change the name of it on the Design tab -- I'll change ours to OrderListObject. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildinganExcelClientagainstLOBD_E5CD/OBAExcelClient2_4.jpg"&gt;&lt;img height="271" alt="OBAExcelClient2" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildinganExcelClientagainstLOBD_E5CD/OBAExcelClient2_thumb_1.jpg" width="709" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Unfortunately it drops all the columns regardless if we select a drop target of none or not. Right click on the column and select Delete from the drop-down menu to delete a column (don't press the delete key). I'm going to remove the first three and the last three columns that it dropped. You'll also want to set any date fields you're displaying in the sheet to Text format. This is to work around a bug in the ListObject where it won't let you change date values if the formatting isn't set to text. You do this by selecting the column then right-click, select Format Cells, and then select Text from the list. &lt;/p&gt;

&lt;p&gt;We can be explicit about setting our data source and binding to columns in the startup event handler:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Public Class &lt;/span&gt;Sheet1

    &lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;Sheet1_Startup() &lt;span style="color: blue"&gt;Handles Me&lt;/span&gt;.Startup
        &lt;span style="color: blue"&gt;Dim &lt;/span&gt;myApp = NorthwindExcelClient.Globals.ThisWorkbook
        &lt;span style="color: blue"&gt;Me&lt;/span&gt;.OrderBindingSource.DataSource = myApp.OrderList

        &lt;span style="color: blue"&gt;Me&lt;/span&gt;.OrderListObject.SetDataBinding(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.OrderBindingSource, &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;, _
                                          &lt;span style="color: #a31515"&gt;&amp;quot;ShippedDate&amp;quot;&lt;/span&gt;, _
                                          &lt;span style="color: #a31515"&gt;&amp;quot;Freight&amp;quot;&lt;/span&gt;, _
                                          &lt;span style="color: #a31515"&gt;&amp;quot;ShipName&amp;quot;&lt;/span&gt;, _
                                          &lt;span style="color: #a31515"&gt;&amp;quot;ShipAddress&amp;quot;&lt;/span&gt;, _
                                          &lt;span style="color: #a31515"&gt;&amp;quot;ShipCity&amp;quot;&lt;/span&gt;, _
                                          &lt;span style="color: #a31515"&gt;&amp;quot;ShipRegion&amp;quot;&lt;/span&gt;, _
                                          &lt;span style="color: #a31515"&gt;&amp;quot;ShipPostalCode&amp;quot;&lt;/span&gt;, _
                                          &lt;span style="color: #a31515"&gt;&amp;quot;ShipCountry&amp;quot;&lt;/span&gt;)

        &lt;span style="color: blue"&gt;Me&lt;/span&gt;.OrderListObject.AutoSelectRows = &lt;span style="color: blue"&gt;True

        &lt;/span&gt;myApp.LoadOrders()
    &lt;span style="color: blue"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Also notice the last line calls a method on ThisWorkbook to load the orders. Let's see how we can do this by writing a query against our ADO.NET data service.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Querying and Saving Orders via our Data Service&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we can return back to our MyOrdersList and write a method for returning the list of orders that have not yet been shipped. Here I call the service to return a list of unshipped orders, add them all to MyOrderList and then raise the list changed event once to notify the Excel ListObject to refresh it's UI:&lt;/p&gt;

&lt;pre class="code"&gt; &lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
&lt;/span&gt;&lt;span style="color: green"&gt;''' Queries the open orders from the data service 
''' and returns the number of orders returned in the results
''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
&lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;number of orders returned from the service&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/returns&amp;gt;
&lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;Public Function &lt;/span&gt;LoadOrders() &lt;span style="color: blue"&gt;As Integer
    Dim &lt;/span&gt;isLoaded = &lt;span style="color: blue"&gt;True
    Me&lt;/span&gt;.Clear()

    &lt;span style="color: blue"&gt;Me&lt;/span&gt;.RaiseListChangedEvents = &lt;span style="color: blue"&gt;False

    Dim &lt;/span&gt;orders = &lt;span style="color: blue"&gt;From &lt;/span&gt;o &lt;span style="color: blue"&gt;In &lt;/span&gt;DataServiceContext.Orders _
                 &lt;span style="color: blue"&gt;Where &lt;/span&gt;o.ShippedDate &lt;span style="color: blue"&gt;Is Nothing &lt;/span&gt;_
                 &lt;span style="color: blue"&gt;Order By &lt;/span&gt;o.OrderDate

    &lt;span style="color: blue"&gt;For Each &lt;/span&gt;o &lt;span style="color: blue"&gt;In &lt;/span&gt;orders
        &lt;span style="color: blue"&gt;Me&lt;/span&gt;.Add(o)
    &lt;span style="color: blue"&gt;Next

    Me&lt;/span&gt;.RaiseListChangedEvents = &lt;span style="color: blue"&gt;True
    Me&lt;/span&gt;.OnListChanged(&lt;span style="color: blue"&gt;New &lt;/span&gt;ListChangedEventArgs(ListChangedType.Reset, 0))
    &lt;span style="color: blue"&gt;Return Me&lt;/span&gt;.Count
&lt;span style="color: blue"&gt;End Function&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;We're also going to need a way to load the order details, shipper and product entities when requested. This will happen as the user selects rows of data -- we need to display these details in our &lt;a href="http://msdn.microsoft.com/en-us/library/7we49he1.aspx" target="_blank"&gt;Action Pane&lt;/a&gt;. By default these entity references and collections are not loaded, we need to do this explicitly. This is a good thing in our case because it avoids transferring unnecessary data if the user doesn't select the Order row in the sheet. &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
&lt;/span&gt;&lt;span style="color: green"&gt;''' Loads the Order Details and Product information from the data 
'''  service and returns the OrderDetails for the specified order.
''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
&lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;o&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
&lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;Public Sub &lt;/span&gt;LoadOrderDetails(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;o &lt;span style="color: blue"&gt;As &lt;/span&gt;Order)
    &lt;span style="color: blue"&gt;If &lt;/span&gt;(o &lt;span style="color: blue"&gt;IsNot Nothing&lt;/span&gt;) &lt;span style="color: blue"&gt;Then
        If &lt;/span&gt;o.Shipper &lt;span style="color: blue"&gt;Is Nothing Then
            Me&lt;/span&gt;.DataServiceContext.LoadProperty(o, &lt;span style="color: #a31515"&gt;&amp;quot;Shipper&amp;quot;&lt;/span&gt;)
        &lt;span style="color: blue"&gt;End If
        If &lt;/span&gt;o.Order_Details &lt;span style="color: blue"&gt;Is Nothing OrElse &lt;/span&gt;o.Order_Details.Count = 0 &lt;span style="color: blue"&gt;Then
            Me&lt;/span&gt;.DataServiceContext.LoadProperty(o, &lt;span style="color: #a31515"&gt;&amp;quot;Order_Details&amp;quot;&lt;/span&gt;)
            &lt;span style="color: blue"&gt;For Each &lt;/span&gt;detail &lt;span style="color: blue"&gt;In &lt;/span&gt;o.Order_Details
                detail.Order = o
                &lt;span style="color: blue"&gt;If &lt;/span&gt;detail.Product &lt;span style="color: blue"&gt;Is Nothing Then
                    Me&lt;/span&gt;.DataServiceContext.LoadProperty(detail, &lt;span style="color: #a31515"&gt;&amp;quot;Product&amp;quot;&lt;/span&gt;)
                &lt;span style="color: blue"&gt;End If
            Next
        End If
    End If
End Sub&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Finally we need a method that submits changes back to the data service. This is easily done by calling SaveChanges on the service context which sends all the changes we made in the client through the service. Note here that we are not sending them in a single batch, therefore if one order fails to update the ones before the failure will still be saved. You may need to put more robust error handling here depending on what kind of failures you anticipate in your applications. Simple error handling is done for this example in the Action Pane (we'll get there next).&lt;/p&gt;

&lt;pre class="code"&gt;    &lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' Saves the customer changes back to the service.
    ''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;true if save was successful, otherwise an exception is thrown&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/returns&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
    &lt;/span&gt;&lt;span style="color: blue"&gt;Public Function &lt;/span&gt;SaveChanges() &lt;span style="color: blue"&gt;As Boolean
        Dim &lt;/span&gt;saved &lt;span style="color: blue"&gt;As Boolean
        Try
            &lt;/span&gt;_isSaving = &lt;span style="color: blue"&gt;True
            Me&lt;/span&gt;.DataServiceContext.SaveChanges()
            _hasChanges = &lt;span style="color: blue"&gt;False
            &lt;/span&gt;saved = &lt;span style="color: blue"&gt;True
        Finally
            &lt;/span&gt;_isSaving = &lt;span style="color: blue"&gt;False
        End Try

        Return &lt;/span&gt;saved
    &lt;span style="color: blue"&gt;End Function
&lt;br /&gt;End Class&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Creating the Excel Action Pane Using WPF&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;Now we're ready to design our Action Pane that will display the order details as well as provide a status message area and a Save and Refresh button. Refresh will re-load the orders from the service and Save will send the changes back. (Later we'll also hook up Excel's save button to do the same thing.)&lt;/p&gt;

&lt;p&gt;I've showed how to use WPF in Office applications before when we &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/07/oba-part-2-building-and-outlook-client-against-lob-data.aspx" target="_blank"&gt;built the Outlook Add-In in Part 2.&lt;/a&gt; It's the same technique here -- use the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.elementhost.aspx" target="_blank"&gt;Winforms ElementHost&lt;/a&gt; as a container for your WPF control. So let's create our WPF user control -- add a new item to the project and select WPF category on the left and then choose WPF User Control. I named it WPFActionPane and click OK. &lt;/p&gt;

&lt;p&gt;The reason for using WPF in this case is so that we could really get a nice look-and-feel that matches Excel's colors. Additionally we can easily provide a couple simple animations so that users notice the control on the right-hand side of the spreadsheet -- this is the default location of an Action Pane. So here's the layout of the control and the styles used to make the read-only GridView have a nice Excel-friendly look:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;UserControl &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;WPFActionPane&amp;quot;
    &lt;/span&gt;&lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
    &lt;/span&gt;&lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;  
             &lt;/span&gt;&lt;span style="color: red"&gt;MinHeight&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;200&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;MinWidth&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;200&amp;quot; 
             &lt;/span&gt;&lt;span style="color: red"&gt;VerticalContentAlignment&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Stretch&amp;quot; 
             &lt;/span&gt;&lt;span style="color: red"&gt;HorizontalContentAlignment&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Stretch&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;400&amp;quot; &amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;UserControl.Resources&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Storyboard &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;LoadingStoryBoard&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DoubleAnimation
                    &lt;/span&gt;&lt;span style="color: red"&gt;Storyboard.TargetName&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ListGrid&amp;quot;
                    &lt;/span&gt;&lt;span style="color: red"&gt;Storyboard.TargetProperty&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Opacity&amp;quot;
                    &lt;/span&gt;&lt;span style="color: red"&gt;From&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0.0&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;To&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;1.0&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Duration&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0:0:0.5&amp;quot; 
                    &lt;/span&gt;&lt;span style="color: red"&gt;AutoReverse&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;False&amp;quot;  /&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Storyboard&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Storyboard &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;UpdateStoryBoard&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ColorAnimation &lt;/span&gt;&lt;span style="color: red"&gt;From&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;White&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;To&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Yellow&amp;quot; 
                    &lt;/span&gt;&lt;span style="color: red"&gt;Storyboard.TargetName&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;txtStatus&amp;quot; 
                    &lt;/span&gt;&lt;span style="color: red"&gt;Storyboard.TargetProperty&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Background.Color&amp;quot; 
                    &lt;/span&gt;&lt;span style="color: red"&gt;AutoReverse&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;True&amp;quot; /&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ColorAnimation &lt;/span&gt;&lt;span style="color: red"&gt;From&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Black&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;To&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;White&amp;quot; 
                    &lt;/span&gt;&lt;span style="color: red"&gt;Storyboard.TargetName&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;txtStatus&amp;quot; 
                    &lt;/span&gt;&lt;span style="color: red"&gt;Storyboard.TargetProperty&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Foreground.Color&amp;quot; 
                    &lt;/span&gt;&lt;span style="color: red"&gt;AutoReverse&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;True&amp;quot; /&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Storyboard&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Style &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;GridViewStyle&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;TargetType&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;TextBox&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Margin&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;-3,0,-9,-3&amp;quot; /&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Cursor&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Arrow&amp;quot; /&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;IsReadOnly&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;True&amp;quot; /&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;BorderBrush&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;#B8CCE4&amp;quot; /&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Style&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Style &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ListViewStyle&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;TargetType&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ListView&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Background&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter.Value&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;LinearGradientBrush &lt;/span&gt;&lt;span style="color: red"&gt;EndPoint&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0.5,1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;StartPoint&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0.5,0&amp;quot;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;GradientStop &lt;/span&gt;&lt;span style="color: red"&gt;Color&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;#4F81BD&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Offset&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0&amp;quot;/&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;GradientStop &lt;/span&gt;&lt;span style="color: red"&gt;Color&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;White&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Offset&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;1.0&amp;quot;/&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;LinearGradientBrush&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter.Value&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Style&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Style &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ListViewItemStyle&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;TargetType&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ListViewItem&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Background&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Transparent&amp;quot;/&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;BorderBrush&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Transparent&amp;quot;/&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;BorderThickness&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;1&amp;quot;/&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;HorizontalContentAlignment&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Stretch&amp;quot; /&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;VerticalContentAlignment&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Stretch&amp;quot; /&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Height&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;22&amp;quot; /&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;&amp;lt;!--Removes the row higlight--&amp;gt;
    &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Template&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter.Value&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ControlTemplate &lt;/span&gt;&lt;span style="color: red"&gt;TargetType&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Type &lt;/span&gt;&lt;span style="color: red"&gt;ListViewItem&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;GridViewRowPresenter 
                    &lt;/span&gt;&lt;span style="color: red"&gt;SnapsToDevicePixels&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateBinding &lt;/span&gt;&lt;span style="color: red"&gt;SnapsToDevicePixels&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; 
                    &lt;/span&gt;&lt;span style="color: red"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateBinding &lt;/span&gt;&lt;span style="color: red"&gt;VerticalContentAlignment&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; 
                    &lt;/span&gt;&lt;span style="color: red"&gt;Grid.RowSpan&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;2&amp;quot;/&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ControlTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter.Value&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Style&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Style &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Key&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;GridViewColumnHeaderStyle&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;TargetType&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;GridViewColumnHeader&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Background&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;#4F81BD&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Foreground&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;#DBE5F1&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;FontWeight&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Bold&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;HorizontalContentAlignment&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Left&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;BorderThickness&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;2&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Focusable&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;False&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;BorderBrush&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter.Value&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;LinearGradientBrush &lt;/span&gt;&lt;span style="color: red"&gt;EndPoint&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0.5,1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;StartPoint&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0.5,0&amp;quot;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;GradientStop &lt;/span&gt;&lt;span style="color: red"&gt;Color&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;White&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Offset&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0&amp;quot;/&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;GradientStop &lt;/span&gt;&lt;span style="color: red"&gt;Color&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;#B8CCE4&amp;quot;  &lt;/span&gt;&lt;span style="color: red"&gt;Offset&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;1.0&amp;quot;/&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;LinearGradientBrush&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter.Value&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter &lt;/span&gt;&lt;span style="color: red"&gt;Property&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Template&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter.Value&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ControlTemplate &lt;/span&gt;&lt;span style="color: red"&gt;TargetType&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Type &lt;/span&gt;&lt;span style="color: red"&gt;GridViewColumnHeader&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid &lt;/span&gt;&lt;span style="color: red"&gt;SnapsToDevicePixels&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;True&amp;quot;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Border &lt;/span&gt;&lt;span style="color: red"&gt;BorderThickness&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0,0,0,1&amp;quot; 
                            &lt;/span&gt;&lt;span style="color: red"&gt;BorderBrush&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateBinding &lt;/span&gt;&lt;span style="color: red"&gt;Border&lt;/span&gt;&lt;span style="color: blue"&gt;.&lt;/span&gt;&lt;span style="color: red"&gt;BorderBrush&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; 
                            &lt;/span&gt;&lt;span style="color: red"&gt;Background&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateBinding &lt;/span&gt;&lt;span style="color: red"&gt;Panel&lt;/span&gt;&lt;span style="color: blue"&gt;.&lt;/span&gt;&lt;span style="color: red"&gt;Background&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;HeaderBorder&amp;quot;&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Border &lt;/span&gt;&lt;span style="color: red"&gt;Padding&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateBinding &lt;/span&gt;&lt;span style="color: red"&gt;Control&lt;/span&gt;&lt;span style="color: blue"&gt;.&lt;/span&gt;&lt;span style="color: red"&gt;Padding&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Grid.RowSpan&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;2&amp;quot;&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ContentPresenter 
                            &lt;/span&gt;&lt;span style="color: red"&gt;RecognizesAccessKey&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;True&amp;quot; 
                            &lt;/span&gt;&lt;span style="color: red"&gt;Content&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateBinding &lt;/span&gt;&lt;span style="color: red"&gt;ContentControl&lt;/span&gt;&lt;span style="color: blue"&gt;.&lt;/span&gt;&lt;span style="color: red"&gt;Content&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; 
                            &lt;/span&gt;&lt;span style="color: red"&gt;ContentTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateBinding &lt;/span&gt;&lt;span style="color: red"&gt;ContentControl&lt;/span&gt;&lt;span style="color: blue"&gt;.&lt;/span&gt;&lt;span style="color: red"&gt;ContentTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; 
                            &lt;/span&gt;&lt;span style="color: red"&gt;ContentStringFormat&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateBinding &lt;/span&gt;&lt;span style="color: red"&gt;ContentControl&lt;/span&gt;&lt;span style="color: blue"&gt;.&lt;/span&gt;&lt;span style="color: red"&gt;ContentStringFormat&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; 
                            &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;HeaderContent&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Margin&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0,0,0,1&amp;quot; 
                            &lt;/span&gt;&lt;span style="color: red"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateBinding &lt;/span&gt;&lt;span style="color: red"&gt;Control&lt;/span&gt;&lt;span style="color: blue"&gt;.&lt;/span&gt;&lt;span style="color: red"&gt;HorizontalContentAlignment&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; 
                            &lt;/span&gt;&lt;span style="color: red"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateBinding &lt;/span&gt;&lt;span style="color: red"&gt;Control&lt;/span&gt;&lt;span style="color: blue"&gt;.&lt;/span&gt;&lt;span style="color: red"&gt;VerticalContentAlignment&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; 
                            &lt;/span&gt;&lt;span style="color: red"&gt;SnapsToDevicePixels&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;TemplateBinding &lt;/span&gt;&lt;span style="color: red"&gt;UIElement&lt;/span&gt;&lt;span style="color: blue"&gt;.&lt;/span&gt;&lt;span style="color: red"&gt;SnapsToDevicePixels&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;
                        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Border&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Border&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ControlTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter.Value&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Setter&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Style&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;UserControl.Resources&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
 &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Auto&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Auto&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;MainGrid&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;RowDefinition &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;50&amp;quot; /&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;RowDefinition &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;50&amp;quot; /&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;RowDefinition &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;140*&amp;quot; /&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;RowDefinition &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;60&amp;quot; /&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid.RowDefinitions&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;StackPanel &lt;/span&gt;&lt;span style="color: red"&gt;Orientation&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Horizontal&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Right&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Top&amp;quot;  
                &lt;/span&gt;&lt;span style="color: red"&gt;Visibility&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Hidden&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ButtonStack&amp;quot;&amp;gt;
       &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Button &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;40&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;cmdSave&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;40&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Margin&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;3&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;ToolTip&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Save&amp;quot;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Image &lt;/span&gt;&lt;span style="color: red"&gt;Source&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;FloppyDisk.png&amp;quot; /&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Button&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Button &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;40&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;cmdRefresh&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;40&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Margin&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;3&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;ToolTip&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Refresh&amp;quot;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Image &lt;/span&gt;&lt;span style="color: red"&gt;Source&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Refresh.png&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Image1&amp;quot; /&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Button&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;StackPanel&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;StackPanel &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Row&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;1&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;txtShipper&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Auto&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;25&amp;quot;
                 &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;=Shipper.CompanyName, &lt;/span&gt;&lt;span style="color: red"&gt;StringFormat&lt;/span&gt;&lt;span style="color: blue"&gt;=Ship &lt;/span&gt;&lt;span style="color: red"&gt;via &lt;/span&gt;\&lt;span style="color: blue"&gt;{&lt;/span&gt;0\&lt;span style="color: blue"&gt;}}&amp;quot;  
                 &lt;/span&gt;&lt;span style="color: red"&gt;Foreground&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;DarkBlue&amp;quot; /&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;txtOrderDate&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Auto&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;25&amp;quot;
                  &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;=OrderDate, &lt;/span&gt;&lt;span style="color: red"&gt;StringFormat&lt;/span&gt;&lt;span style="color: blue"&gt;=Ordered &lt;/span&gt;\&lt;span style="color: blue"&gt;{&lt;/span&gt;0&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;D&lt;/span&gt;\&lt;span style="color: blue"&gt;}}&amp;quot; 
                  &lt;/span&gt;&lt;span style="color: red"&gt;Foreground&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;DarkBlue&amp;quot;/&amp;gt;
       
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;StackPanel&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Image &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Row&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;2&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Source&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;northwindlogo.gif&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;140&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;140&amp;quot; /&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Row&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;2&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Background&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;White&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ListGrid&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ListView 
            &lt;/span&gt;&lt;span style="color: red"&gt;ItemsSource&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;=Order_Details}&amp;quot;
            &lt;/span&gt;&lt;span style="color: red"&gt;Style&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource &lt;/span&gt;&lt;span style="color: red"&gt;ListViewStyle&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;
            &lt;/span&gt;&lt;span style="color: red"&gt;ItemContainerStyle&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource &lt;/span&gt;&lt;span style="color: red"&gt;ListViewItemStyle&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;
            &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ListView1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Margin&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;4&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;IsEnabled&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;True&amp;quot; 
            &lt;/span&gt;&lt;span style="color: red"&gt;BorderThickness&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0&amp;quot; &amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ListView.View&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                 &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;GridView 
                     &lt;/span&gt;&lt;span style="color: red"&gt;ColumnHeaderContainerStyle&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource &lt;/span&gt;&lt;span style="color: red"&gt;GridViewColumnHeaderStyle&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;GridViewColumn &lt;/span&gt;&lt;span style="color: red"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Product&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;150&amp;quot;&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;GridViewColumn.CellTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBox 
                                    &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;=Product.ProductName}&amp;quot; 
                                    &lt;/span&gt;&lt;span style="color: red"&gt;Style&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource &lt;/span&gt;&lt;span style="color: red"&gt;GridViewStyle&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;/&amp;gt;
                            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;GridViewColumn.CellTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;GridViewColumn&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;GridViewColumn &lt;/span&gt;&lt;span style="color: red"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Quantity&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;61&amp;quot;&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;GridViewColumn.CellTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBox 
                                    &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;=Quantity, &lt;/span&gt;&lt;span style="color: red"&gt;StringFormat&lt;/span&gt;&lt;span style="color: blue"&gt;='n0'}&amp;quot; 
                                    &lt;/span&gt;&lt;span style="color: red"&gt;Style&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource &lt;/span&gt;&lt;span style="color: red"&gt;GridViewStyle&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; /&amp;gt;
                            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;GridViewColumn.CellTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;GridViewColumn&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;GridView&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ListView.View&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt; 
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ListView&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
   &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Row&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;3&amp;quot;&amp;gt;
       &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBox &lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;txtStatus&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;TextWrapping&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Wrap&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Background&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Transparent&amp;quot;
              &lt;/span&gt;&lt;span style="color: red"&gt;IsReadOnly&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;True&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;BorderThickness&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;HorizontalContentAlignment&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Stretch&amp;quot; 
              &lt;/span&gt;&lt;span style="color: red"&gt;VerticalScrollBarVisibility&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Auto&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Cursor&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Arrow&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBox&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
     
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Grid&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;UserControl&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The code that calls the load and save on the orders will be here since this control will interact directly with the list of Orders. In the code-behind of the WPFActionPane we'll also animate the control by running the StoryBoards defined in the XAML when we display the order details and when we display status messages at the bottom of the pane. (Note that I've also included the images referred by the XAML above into the project and &lt;a href="http://msdn.microsoft.com/en-us/library/cc165603.aspx" target="_blank"&gt;set their Build Action to Resource&lt;/a&gt; in the properties for the files in the Solution Explorer). &lt;/p&gt;

&lt;p&gt;We will pass the reference to the list of Orders into the control which we can then set as the DataContext. This will trigger all the data bindings to hook up to the currently selected Order's details as noted by the dot syntax in the bindings above. For instance, if we want to display the shipper's company name then we specify the Shipper.CompanyName path on the Order object contained in the list. &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;NorthwindExcelClient.NorthwindService
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Windows.Data
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Windows.Media

&lt;span style="color: blue"&gt;Partial Public Class &lt;/span&gt;WPFActionPane

    &lt;span style="color: blue"&gt;Private &lt;/span&gt;_orderList &lt;span style="color: blue"&gt;As &lt;/span&gt;MyOrderList
    &lt;span style="color: blue"&gt;Public Property &lt;/span&gt;OrderList() &lt;span style="color: blue"&gt;As &lt;/span&gt;MyOrderList
        &lt;span style="color: blue"&gt;Get
            Return &lt;/span&gt;_orderList
        &lt;span style="color: blue"&gt;End Get
        Set&lt;/span&gt;(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As &lt;/span&gt;MyOrderList)
            _orderList = value
            &lt;span style="color: blue"&gt;Me&lt;/span&gt;.DataContext = _orderList
        &lt;span style="color: blue"&gt;End Set
    End Property

    Private Sub &lt;/span&gt;cmdRefresh_Click() &lt;span style="color: blue"&gt;Handles &lt;/span&gt;cmdRefresh.Click
        &lt;span style="color: blue"&gt;Me&lt;/span&gt;.LoadOrders()
    &lt;span style="color: blue"&gt;End Sub

    Private Sub &lt;/span&gt;cmdSave_Click() &lt;span style="color: blue"&gt;Handles &lt;/span&gt;cmdSave.Click
        &lt;span style="color: blue"&gt;Me&lt;/span&gt;.SaveOrders()
    &lt;span style="color: blue"&gt;End Sub
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' Saves changes made to the orders in the sheet
    ''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
    &lt;/span&gt;&lt;span style="color: blue"&gt;Public Function &lt;/span&gt;SaveOrders() &lt;span style="color: blue"&gt;As Boolean
        Dim &lt;/span&gt;msg = &lt;span style="color: #a31515"&gt;&amp;quot;Orders could not be saved.&amp;quot; &lt;/span&gt;&amp;amp; vbCrLf
        &lt;span style="color: blue"&gt;Try
            &lt;/span&gt;&lt;span style="color: green"&gt;'Save changes back to the data service
            &lt;/span&gt;&lt;span style="color: blue"&gt;If Me&lt;/span&gt;.OrderList.SaveChanges() &lt;span style="color: blue"&gt;Then
                &lt;/span&gt;msg = &lt;span style="color: #a31515"&gt;&amp;quot;Orders saved.&amp;quot;
            &lt;/span&gt;&lt;span style="color: blue"&gt;End If

            Me&lt;/span&gt;.SetMessage(msg)

        &lt;span style="color: blue"&gt;Catch &lt;/span&gt;ex &lt;span style="color: blue"&gt;As &lt;/span&gt;Exception
            &lt;span style="color: blue"&gt;Me&lt;/span&gt;.SetMessage(ex.ToString())
        &lt;span style="color: blue"&gt;End Try
    End Function
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' Re-loads the orders that are not shipped yet. 
    ''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
    &lt;/span&gt;&lt;span style="color: blue"&gt;Public Sub &lt;/span&gt;LoadOrders()
        &lt;span style="color: blue"&gt;Dim &lt;/span&gt;msg = &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot;
        &lt;/span&gt;&lt;span style="color: blue"&gt;Try
            Dim &lt;/span&gt;count = &lt;span style="color: blue"&gt;Me&lt;/span&gt;.OrderList.LoadOrders()
            msg = &lt;span style="color: blue"&gt;String&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;{0} orders returned.&amp;quot;&lt;/span&gt;, count)

            &lt;span style="color: blue"&gt;Me&lt;/span&gt;.SetMessage(msg)
            &lt;span style="color: blue"&gt;Me&lt;/span&gt;.ButtonStack.Visibility = Windows.Visibility.Visible
        &lt;span style="color: blue"&gt;Catch &lt;/span&gt;ex &lt;span style="color: blue"&gt;As &lt;/span&gt;Exception
            &lt;span style="color: blue"&gt;Me&lt;/span&gt;.SetMessage(ex.ToString())
        &lt;span style="color: blue"&gt;End Try
    End Sub
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' Show the Order Details in the ListView by moving the position
    ''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;o&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
    &lt;/span&gt;&lt;span style="color: blue"&gt;Public Sub &lt;/span&gt;DisplayOrderDetails(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;o &lt;span style="color: blue"&gt;As &lt;/span&gt;Order)
        &lt;span style="color: blue"&gt;If &lt;/span&gt;o &lt;span style="color: blue"&gt;IsNot Nothing Then
            Me&lt;/span&gt;.OrderList.LoadOrderDetails(o)
            &lt;span style="color: blue"&gt;Dim &lt;/span&gt;view = CollectionViewSource.GetDefaultView(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.DataContext)
            view.MoveCurrentTo(o)

            &lt;span style="color: blue"&gt;Me&lt;/span&gt;.ListGrid.Visibility = Windows.Visibility.Visible
            &lt;span style="color: blue"&gt;Me&lt;/span&gt;.ListView1.SelectedIndex = -1
            &lt;span style="color: blue"&gt;Dim &lt;/span&gt;story = &lt;span style="color: blue"&gt;CType&lt;/span&gt;(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.Resources(&lt;span style="color: #a31515"&gt;&amp;quot;LoadingStoryBoard&amp;quot;&lt;/span&gt;), Animation.Storyboard)
            story.Begin()
        &lt;span style="color: blue"&gt;End If
    End Sub
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' Sets the status message on the control
    ''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;msg&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
    &lt;/span&gt;&lt;span style="color: blue"&gt;Public Sub &lt;/span&gt;SetMessage(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;msg &lt;span style="color: blue"&gt;As String&lt;/span&gt;)
        &lt;span style="color: blue"&gt;Me&lt;/span&gt;.txtStatus.Text = msg
        &lt;span style="color: blue"&gt;Dim &lt;/span&gt;story = &lt;span style="color: blue"&gt;CType&lt;/span&gt;(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.Resources(&lt;span style="color: #a31515"&gt;&amp;quot;UpdateStoryBoard&amp;quot;&lt;/span&gt;), Animation.Storyboard)
        story.Begin()
    &lt;span style="color: blue"&gt;End Sub

End Class&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Now we can create the Action Pane. Add a new item to the project and select Actions Pane Control from the Office group. I named it OrdersActionPane:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildinganExcelClientagainstLOBD_E5CD/OBAExcelClient3_2.jpg"&gt;&lt;img height="352" alt="OBAExcelClient3" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildinganExcelClientagainstLOBD_E5CD/OBAExcelClient3_thumb.jpg" width="587" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now from the toolbox in the WPF Interoperability category you should see the ElementHost, drag that onto the Actions Pane user control, click the smart tag and select the WPFActionPane control as the hosted content and dock it in the parent container. I'm also going to set the font of the OrdersActionPane to Calibri 11 point. &lt;/p&gt;

&lt;p&gt;In the code behind for the OrdersActionPane we need to set the OrderList for the WPF control as well as listen to position changed event on the OrderListBindingSource that is hooked up as the DataSource of the ListObject on Sheet1. When the position changes we need to tell the WPF control to display that Order's details. There are many ways to integrate WPF and Windows Forms to manage currency but we're trying to keep this example straightforward so we'll do it the easy way:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Data.Services.Client
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;NorthwindExcelClient.NorthwindService

&lt;span style="color: blue"&gt;Public Class &lt;/span&gt;OrdersActionsPane

    &lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;OrdersActionsPane_Load() &lt;span style="color: blue"&gt;Handles Me&lt;/span&gt;.Load
        &lt;span style="color: green"&gt;'Pass in our data source to the WPF control
        &lt;/span&gt;&lt;span style="color: blue"&gt;Me&lt;/span&gt;.WpfActionPane1.OrderList = NorthwindExcelClient.Globals.ThisWorkbook.OrderList
        &lt;span style="color: green"&gt;'When the position changes in the spreadsheet, display the order details in the WPF control
        &lt;/span&gt;&lt;span style="color: blue"&gt;AddHandler &lt;/span&gt;NorthwindExcelClient.Globals.Sheet1.MyOrderListBindingSource.PositionChanged, _
                  &lt;span style="color: blue"&gt;AddressOf Me&lt;/span&gt;.DisplayOrderDetails
    &lt;span style="color: blue"&gt;End Sub

    Private Sub &lt;/span&gt;DisplayOrderDetails(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;sender &lt;span style="color: blue"&gt;As Object&lt;/span&gt;, &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;e &lt;span style="color: blue"&gt;As &lt;/span&gt;EventArgs)
        &lt;span style="color: blue"&gt;Dim &lt;/span&gt;source = &lt;span style="color: blue"&gt;TryCast&lt;/span&gt;(sender, BindingSource)
        &lt;span style="color: blue"&gt;If &lt;/span&gt;source &lt;span style="color: blue"&gt;IsNot Nothing Then
            If &lt;/span&gt;source.Position &amp;gt; -1 &lt;span style="color: blue"&gt;Then
                Me&lt;/span&gt;.WpfActionPane1.DisplayOrderDetails(&lt;span style="color: blue"&gt;TryCast&lt;/span&gt;(source.Current, Order))
            &lt;span style="color: blue"&gt;End If
        End If
    End Sub
&lt;/span&gt;&lt;span style="color: blue"&gt;End Class&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Finally we're almost ready to test this out. The last thing we need to do is load the Actions Pane when the application starts as well as expose a LoadOrders to our Sheet. This is because if we're adding charts, pivot tables or other types of controls for data analysis we can't rely on the Action Pane loading the data, we need the sheet to be able to call upon it explicitly. We also will hook up the Excel BeforeSave event so that we can call save on the orders. So back in the ThisWorkbook class:&lt;/p&gt;

&lt;pre class="code"&gt;   &lt;span style="color: blue"&gt;Private &lt;/span&gt;_orderActions &lt;span style="color: blue"&gt;As New &lt;/span&gt;OrdersActionsPane

    &lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;ThisWorkbook_Startup(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;sender &lt;span style="color: blue"&gt;As Object&lt;/span&gt;, _
                                     &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;e &lt;span style="color: blue"&gt;As &lt;/span&gt;System.EventArgs) &lt;span style="color: blue"&gt;Handles Me&lt;/span&gt;.Startup
        &lt;span style="color: green"&gt;'Load the action pane
        &lt;/span&gt;&lt;span style="color: blue"&gt;Me&lt;/span&gt;.ActionsPane.Controls.Add(_orderActions)
    &lt;span style="color: blue"&gt;End Sub

    Public Sub &lt;/span&gt;LoadOrders()
        _orderActions.WpfActionPane1.LoadOrders()
    &lt;span style="color: blue"&gt;End Sub

    Private Sub &lt;/span&gt;ThisWorkbook_BeforeSave(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;SaveAsUI &lt;span style="color: blue"&gt;As Boolean&lt;/span&gt;, _
                                        &lt;span style="color: blue"&gt;ByRef &lt;/span&gt;Cancel &lt;span style="color: blue"&gt;As Boolean&lt;/span&gt;) &lt;span style="color: blue"&gt;Handles Me&lt;/span&gt;.BeforeSave
        _orderActions.WpfActionPane1.SaveOrders()
    &lt;span style="color: blue"&gt;End Sub
End Class&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;Hit F5 and try it out. You will see all the Orders that have not shipped. As you select a row, the details are displayed in the Action Pane and an animation that shows the Northwind logo fades into and out of view so that it catches the user's attention without annoying them ;-). Modify any of the fields in the Sheet and click save to save your changes back to the service. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding a Pivot Table and Chart&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The final thing we want to do is add a pivot table and a pie chart to our Sheet that will display a breakdown of cities we're shipping to. In the designer for Sheet1 select the first cell and then go to the Insert tab. On the left select the arrow under the PivotTable and select PivotChart. A dialog will open which allows you to select the location of the PivotChart. Here I'm just adding it under the ListObject, it will automatically move down as orders come back from the data service. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildinganExcelClientagainstLOBD_E5CD/OBAExcelClient4_2.jpg"&gt;&lt;img height="290" alt="OBAExcelClient4" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildinganExcelClientagainstLOBD_E5CD/OBAExcelClient4_thumb.jpg" width="606" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now you move into specifying the PivotTable fields and values through Excel like you normally would. Here I'm adding the ShipCity as both a label and a value, which automatically assumes a count. I also right-click on the chart and am allowed to change the chart type to a Pie Chart:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildinganExcelClientagainstLOBD_E5CD/OBAExcelClient5_2.jpg"&gt;&lt;img height="393" alt="OBAExcelClient5" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildinganExcelClientagainstLOBD_E5CD/OBAExcelClient5_thumb.jpg" width="606" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We're not quite done though. In order to get our PivotTable to update when the data is retrieved from the service we need to add some code to handle this. First name the PivotTable by right-clicking on it and selecting PivotTable Options -- I named it PivotTableShipCity. Now in the code behind we can handle the ListChanged event on the BindingSource which bubbles up what we're doing in our MyOrdersList class -- when we load the orders in the LoadOrders method, we raise the ListChangedEvent and pass a &amp;quot;Reset&amp;quot; parameter. Now we can check that here:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;MyOrderListBindingSource_ListChanged(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;sender &lt;span style="color: blue"&gt;As Object&lt;/span&gt;, _
            &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;e &lt;span style="color: blue"&gt;As &lt;/span&gt;System.ComponentModel.ListChangedEventArgs) _
            &lt;span style="color: blue"&gt;Handles &lt;/span&gt;MyOrderListBindingSource.ListChanged

    &lt;span style="color: blue"&gt;If &lt;/span&gt;e.ListChangedType = System.ComponentModel.ListChangedType.Reset &lt;span style="color: blue"&gt;Then

        Dim &lt;/span&gt;table = &lt;span style="color: blue"&gt;TryCast&lt;/span&gt;(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.PivotTables(&lt;span style="color: #a31515"&gt;&amp;quot;PivotTableShipCity&amp;quot;&lt;/span&gt;), Excel.PivotTable)
        &lt;span style="color: blue"&gt;If &lt;/span&gt;table &lt;span style="color: blue"&gt;IsNot Nothing Then
            &lt;/span&gt;table.RefreshTable()
        &lt;span style="color: blue"&gt;End If
        Me&lt;/span&gt;.MyOrderListBindingSource.MoveFirst()

    &lt;span style="color: blue"&gt;End If
End Sub&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Now when we hit F5 we will see the open orders come down into the spreadsheet and the pie chart will update to display our Excel data visualization. Nice!&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildinganExcelClientagainstLOBD_E5CD/OBAExcelClient6_2.jpg"&gt;&lt;img height="489" alt="OBAExcelClient6" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart4BuildinganExcelClientagainstLOBD_E5CD/OBAExcelClient6_thumb.jpg" width="664" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I've updated &lt;a href="http://code.msdn.microsoft.com/OBANorthwind" target="_blank"&gt;our sample on Code Gallery&lt;/a&gt; with a new release that includes this Excel client so have a look. &lt;/p&gt;

&lt;p&gt;Now that we understand what our shipping department is doing we can build out our SharePoint workflow. It will need to parse the purchase order using the &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/12/oba-part-3-storing-and-reading-data-in-word-documents.aspx" target="_blank"&gt;code from part 3&lt;/a&gt; and it will also need to update the order status based on the change made here to the ShippedDate field. We don't want our Excel client to be tightly coupled to SharePoint so we'll need to think about how we can achieve this all from our SharePoint Workflow. Until next time...&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9466700" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Article/default.aspx">Article</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Office/default.aspx">Office</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/ADO.NET+Data+Services/default.aspx">ADO.NET Data Services</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VSTO/default.aspx">VSTO</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/OBA/default.aspx">OBA</category></item><item><title>OBA Part 3 - Storing and Reading Data in Word Documents</title><link>http://blogs.msdn.com/bethmassi/archive/2009/02/12/oba-part-3-storing-and-reading-data-in-word-documents.aspx</link><pubDate>Fri, 13 Feb 2009 04:55:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9416665</guid><dc:creator>Beth Massi</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9416665.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9416665</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9416665</wfw:comment><description>&lt;p&gt;In my last few posts we've been building a simple Office Business Application (OBA) for the new Northwind Traders. If you missed them:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/03/oba-part-1-exposing-line-of-business-data.aspx" target="_blank"&gt;OBA Part 1 - Exposing Line-of-Business Data&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/07/oba-part-2-building-and-outlook-client-against-lob-data.aspx" target="_blank"&gt;OBA Part 2 - Building and Outlook Client against LOB Data&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In this post I'm going to talk about how we can create a purchase order in Word 2007 that contains data about the items being purchased and how we can query that data and place it into our database. We'll use this code as a basis for our SharePoint Workflow which we will build out in the next post. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart3ReadingDatafromWordDocuments_DE22/WordOBADiagram_2.jpg"&gt;&lt;img style="margin: 0px 10px 0px 0px" height="375" alt="WordOBADiagram" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart3ReadingDatafromWordDocuments_DE22/WordOBADiagram_thumb.jpg" width="389" align="left" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;If you recall &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/02/building-an-office-business-application-for-techready-8.aspx" target="_blank"&gt;our architecture diagram of our Northwind Traders OBA&lt;/a&gt; involved our Sales Reps submitting purchase orders as Word 2007 documents up to SharePoint which kicked off a workflow to parse the document and update the database with the order data through our data service.&lt;/p&gt;  &lt;p&gt;This allows us to store the unstructured document on SharePoint and the structured order data in our database. &lt;/p&gt;  &lt;p&gt;However before we build out the SharePoint Workflow we need a clean way to store and then retrieve the structured order data inside the Word 2007 document. Since Word 2007 documents are Open XML we can use the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c6e744e5-36e9-45f5-8d8c-331df206e0d0&amp;amp;DisplayLang=en" target="_blank"&gt;Open XML SDK&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/bb384460.aspx" target="_blank"&gt;LINQ to XML&lt;/a&gt; to easily parse the document. (I've talked about how to &lt;a href="http://blogs.msdn.com/bethmassi/archive/2008/07/30/accessing-openxml-document-parts-with-the-openxml-sdk.aspx" target="_blank"&gt;manipulate documents with Open XML SDK before here&lt;/a&gt;.) &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Content Controls&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;One way to store data in an Word 2007 document is by using content controls. These allow you to define specific data areas/fields in the document which are then bound to XML that is placed inside the document. When users enter data into these areas of the document the data is stored as a CustomXML Part inside the document. You can use &lt;a href="http://msdn.microsoft.com/en-us/library/bb398244.aspx" target="_blank"&gt;Visual Studio to create content controls and map them to XML&lt;/a&gt; or you can use Word itself. There's also a nifty tool called the &lt;a href="http://www.codeplex.com/dbe" target="_blank"&gt;Word 2007 Content Control Toolkit&lt;/a&gt; that makes the mapping more visual. I'd also highly recommend installing the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=46B6BF86-E35D-4870-B214-4D7B72B02BF9&amp;amp;displaylang=en" target="_blank"&gt;VSTO Power Tools&lt;/a&gt; as well which includes &lt;a href="http://blogs.msdn.com/bethmassi/archive/2008/07/29/handy-visual-studio-add-in-to-view-office-2007-files.aspx" target="_blank"&gt;a VS Add-In for manipulating Open XML documents&lt;/a&gt;. This allows you to look inside the document easily to inspect all the parts directly within Visual Studio.&lt;/p&gt;  &lt;p&gt;So the first thing to do is to create a purchase order template and lay out the content controls on the document. We'll create something very simple using Microsoft Word 2007. On the Developer tab you will see the Controls section. There you can choose which types of controls to lay out on the document. Click the properties button to assign a friendly title and tag to the control. Here I've laid out the minimum information we'll need to submit an order to the system:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart3ReadingDatafromWordDocuments_DE22/wordcc1_2.jpg"&gt;&lt;img height="438" alt="wordcc1" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart3ReadingDatafromWordDocuments_DE22/wordcc1_thumb.jpg" width="672" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Users can write anything else around the content controls but the system only cares about capturing the data we've specified. This gives us the ability to store structured and unstructured data completely inside the .docx file. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Creating and Mapping the XML&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Now we are ready to map the values of the content controls to some custom XML. The XML document for our order looks like this. (Note that there are 10 &amp;lt;OrderDetail&amp;gt; elements I just snipped them for brevity):&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;OrderEntry &lt;/span&gt;&lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;urn:microsoft:examples:oba&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;CustomerID &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;OrderDate &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Shipper &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;OrderDetails&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;OrderDetail&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ProductName &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Quantity &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;OrderDetail&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;br /&gt;&lt;span style="color: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;OrderDetail&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;...&lt;/span&gt;&lt;span style="color: blue"&gt;
  &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;OrderDetails&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;OrderEntry&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Now open up the &lt;a href="http://www.codeplex.com/dbe" target="_blank"&gt;Word 2007 Content Control Toolkit&lt;/a&gt; an open the OrderEntryTemplate.docx. Under Actions select &amp;quot;Create a new Custom XML Part&amp;quot;, switch to edit view, and then paste in the XML:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart3ReadingDatafromWordDocuments_DE22/wordcc2_2.jpg"&gt;&lt;img height="491" alt="wordcc2" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart3ReadingDatafromWordDocuments_DE22/wordcc2_thumb.jpg" width="594" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Next switch to Bind View and then drag the elements onto the content controls on the left. Make sure you select the element first and then drag it.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart3ReadingDatafromWordDocuments_DE22/wordcc3_2.jpg"&gt;&lt;img height="352" alt="wordcc3" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart3ReadingDatafromWordDocuments_DE22/wordcc3_thumb.jpg" width="629" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Once you're done, save the document and then you can open it in Visual Studio if you've loaded the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=46B6BF86-E35D-4870-B214-4D7B72B02BF9&amp;amp;displaylang=en" target="_blank"&gt;VSTO Power Tools&lt;/a&gt;. This will show the Open XML parts of the document and you can expand the customXml folder and see that our XML has been added to the document. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart3ReadingDatafromWordDocuments_DE22/wordcc4_2.jpg"&gt;&lt;img height="379" alt="wordcc4" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart3ReadingDatafromWordDocuments_DE22/wordcc4_thumb.jpg" width="660" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;If you back into Word and fill out the content controls and then view the document in Visual Studio again, you will see that the item1.xml custom XML part will contain the data we entered. &lt;/p&gt;

&lt;p&gt;Now that we have a purchase order template we can give this to our sales reps who can collaborate with our high volume customers via email to fill it out. They can then submit the purchase orders to a SharePoint list that can run a workflow to extract the order data and update the database through the data service. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using the Open XML SDK to Retrieve the Order Data&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The easiest way to programmatically manipulate Office 2007 Open XML documents is by using the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c6e744e5-36e9-45f5-8d8c-331df206e0d0&amp;amp;DisplayLang=en" target="_blank"&gt;Open XML SDK&lt;/a&gt;. Once you install it you can then Add Reference to the DocumentFormat.OpenXML assembly. In order to use LINQ to XML you'll also need a reference to System.Core and System.Xml.Linq. These are imported automatically when you create a new project in Visual Studio 2008. You'll also need to &lt;a href="http://msdn.microsoft.com/en-us/library/cc668183.aspx" target="_blank"&gt;add a Service Reference to the ADO.NET Data Service&lt;/a&gt; like &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/01/09/using-ado-net-data-services.aspx" target="_blank"&gt;I've shown before&lt;/a&gt;. So let's start simple and just create a console application for now called NorthwindOrderDocParser. Later we'll talk about moving this to a SharePoint workflow. &lt;/p&gt;

&lt;p&gt;Before we start parsing the document let's create a couple simple classes that store the data we're extracting from our document.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
&lt;/span&gt;&lt;span style="color: green"&gt;''' These classes represents the order data that is inside the Word Document. 
''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
&lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;Public Class &lt;/span&gt;DocumentOrderData

    &lt;span style="color: blue"&gt;Sub New&lt;/span&gt;(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;customerID &lt;span style="color: blue"&gt;As String&lt;/span&gt;, &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;orderDate &lt;span style="color: blue"&gt;As Date&lt;/span&gt;, &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;shipperName &lt;span style="color: blue"&gt;As String&lt;/span&gt;)
        _CustomerID = customerID
        _OrderDate = orderDate
        _Shipper = shipperName
    &lt;span style="color: blue"&gt;End Sub

    Private &lt;/span&gt;_CustomerID &lt;span style="color: blue"&gt;As String
    Public Property &lt;/span&gt;CustomerID() &lt;span style="color: blue"&gt;As String
        Get
            Return &lt;/span&gt;_CustomerID
        &lt;span style="color: blue"&gt;End Get
        Set&lt;/span&gt;(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As String&lt;/span&gt;)
            _CustomerID = value
        &lt;span style="color: blue"&gt;End Set
    End Property

    Private &lt;/span&gt;_OrderDate &lt;span style="color: blue"&gt;As Date
    Public Property &lt;/span&gt;OrderDate() &lt;span style="color: blue"&gt;As Date
        Get
            Return &lt;/span&gt;_OrderDate
        &lt;span style="color: blue"&gt;End Get
        Set&lt;/span&gt;(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As Date&lt;/span&gt;)
            _OrderDate = value
        &lt;span style="color: blue"&gt;End Set
    End Property

    Private &lt;/span&gt;_Shipper &lt;span style="color: blue"&gt;As String
    Public Property &lt;/span&gt;Shipper() &lt;span style="color: blue"&gt;As String
        Get
            Return &lt;/span&gt;_Shipper
        &lt;span style="color: blue"&gt;End Get
        Set&lt;/span&gt;(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As String&lt;/span&gt;)
            &lt;span style="color: blue"&gt;If &lt;/span&gt;value &lt;span style="color: blue"&gt;Is Nothing OrElse &lt;/span&gt;value.Trim = &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;Then
                &lt;/span&gt;value = &lt;span style="color: #a31515"&gt;&amp;quot;Speedy Express&amp;quot;
            &lt;/span&gt;&lt;span style="color: blue"&gt;End If
            &lt;/span&gt;_Shipper = value
        &lt;span style="color: blue"&gt;End Set
    End Property

    Private &lt;/span&gt;_details &lt;span style="color: blue"&gt;As New &lt;/span&gt;List(&lt;span style="color: blue"&gt;Of &lt;/span&gt;Detail)
    &lt;span style="color: blue"&gt;Public ReadOnly Property &lt;/span&gt;Details() &lt;span style="color: blue"&gt;As &lt;/span&gt;List(&lt;span style="color: blue"&gt;Of &lt;/span&gt;Detail)
        &lt;span style="color: blue"&gt;Get
            Return &lt;/span&gt;_details
        &lt;span style="color: blue"&gt;End Get
    End Property

    Public Class &lt;/span&gt;Detail
        &lt;span style="color: blue"&gt;Sub New&lt;/span&gt;(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;productName &lt;span style="color: blue"&gt;As String&lt;/span&gt;, &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;quantity &lt;span style="color: blue"&gt;As Short&lt;/span&gt;)
            _ProductName = productName
            _Quantity = quantity
        &lt;span style="color: blue"&gt;End Sub

        Private &lt;/span&gt;_ProductName &lt;span style="color: blue"&gt;As String
        Public Property &lt;/span&gt;ProductName() &lt;span style="color: blue"&gt;As String
            Get
                Return &lt;/span&gt;_ProductName
            &lt;span style="color: blue"&gt;End Get
            Set&lt;/span&gt;(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As String&lt;/span&gt;)
                _ProductName = value
            &lt;span style="color: blue"&gt;End Set
        End Property

        Private &lt;/span&gt;_Quantity &lt;span style="color: blue"&gt;As Short
        Public Property &lt;/span&gt;Quantity() &lt;span style="color: blue"&gt;As Short
            Get
                Return &lt;/span&gt;_Quantity
            &lt;span style="color: blue"&gt;End Get
            Set&lt;/span&gt;(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As Short&lt;/span&gt;)
                _Quantity = value
            &lt;span style="color: blue"&gt;End Set
        End Property
    End Class
End Class&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Next, let's add a schema for the OrderEntry XML data that is contained in the document. This will give us &lt;a href="http://msdn.microsoft.com/en-us/library/bb531325.aspx" target="_blank"&gt;IntelliSense on our XML&lt;/a&gt; when we're using LINQ to XML. We can just open the document in Visual Studio like before and copy the OrderEntry XML data into the clipboard. Then we can Add a new &lt;a href="http://msdn.microsoft.com/en-us/library/cc442691.aspx" target="_blank"&gt;XML to Schema&lt;/a&gt; Item and paste into the Wizard's dialog box. This will infer the schema and place the XSD file into the project automatically for us. Notice that I specified a namespace on our OrderEntry XML data. We now can import this namespace into our main program along with a few other .NET namespaces we'll need:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: green"&gt;'Reference to our data service and data entities:
&lt;/span&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;NorthwindOrderDocParser.NorthwindService
&lt;span style="color: green"&gt;'Open XML SDK:
&lt;/span&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;DocumentFormat.OpenXml.Packaging
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.IO
&lt;span style="color: green"&gt;'Default XML Namespace:
&lt;/span&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #b96464"&gt;xmlns&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;urn:microsoft:examples:oba&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;We are almost ready to start writing our main program to parse the purchase order. First we need a test document. For this test I filled out the following information in a document called MyTestOrder.docx.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart3ReadingDatafromWordDocuments_DE22/wordcc5_2.jpg"&gt;&lt;img height="540" alt="wordcc5" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart3ReadingDatafromWordDocuments_DE22/wordcc5_thumb.jpg" width="654" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now we can write our main program:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Module &lt;/span&gt;Module1

    &lt;span style="color: blue"&gt;Sub &lt;/span&gt;Main()
        &lt;span style="color: blue"&gt;Try
            Dim &lt;/span&gt;docFile = &lt;span style="color: blue"&gt;My&lt;/span&gt;.Computer.FileSystem.GetFileInfo(&lt;span style="color: #a31515"&gt;&amp;quot;MyTestOrder.docx&amp;quot;&lt;/span&gt;)

            &lt;span style="color: blue"&gt;Dim &lt;/span&gt;docData &lt;span style="color: blue"&gt;As &lt;/span&gt;DocumentOrderData
            &lt;span style="color: blue"&gt;Using &lt;/span&gt;sr = docFile.OpenRead()
                &lt;span style="color: green"&gt;'Attempt to parse the document for order data
                &lt;/span&gt;docData = ParseOrderDocument(sr)
                sr.Close()
            &lt;span style="color: blue"&gt;End Using

            If &lt;/span&gt;docData &lt;span style="color: blue"&gt;IsNot Nothing Then
                Dim &lt;/span&gt;employeeEmail = &lt;span style="color: #a31515"&gt;&amp;quot;sales@nwtraders.com&amp;quot;

                &lt;/span&gt;&lt;span style="color: green"&gt;'Attempt to add the order data through the service
                &lt;/span&gt;AddNewOrder(docData, employeeEmail)
                Console.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;Order saved successfully.&amp;quot;&lt;/span&gt;)
            &lt;span style="color: blue"&gt;Else
                &lt;/span&gt;Console.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;No order data was found in the document.&amp;quot;&lt;/span&gt;)
            &lt;span style="color: blue"&gt;End If

        Catch &lt;/span&gt;ex &lt;span style="color: blue"&gt;As &lt;/span&gt;Exception
            Console.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;Order could not be processed.&amp;quot; &lt;/span&gt;&amp;amp; vbCrLf &amp;amp; ex.ToString())
        &lt;span style="color: blue"&gt;End Try

        &lt;/span&gt;Console.ReadLine()
    &lt;span style="color: blue"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The ParseOrderDocument method is going to need to grab the XML data from our Custom XML parts as we iterate over the part collection. It's a collection because there can actually be many Custom XML definitions in our document. In order to make grabbing the XML data from the parts easier let's create an &lt;a href="http://msdn.microsoft.com/en-us/library/bb384936.aspx" target="_blank"&gt;Extension method&lt;/a&gt; that extends the OpenXMLPart type. I like to place Extension methods in a separate file called Extensions.vb:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;DocumentFormat.OpenXml.Packaging
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.IO
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Xml

&lt;span style="color: blue"&gt;Module &lt;/span&gt;Extensions

    &lt;span style="color: green"&gt;' Create an extension method so we can easily access the part XML
    &lt;/span&gt;&amp;lt;System.Runtime.CompilerServices.Extension()&amp;gt; _
    &lt;span style="color: blue"&gt;Function &lt;/span&gt;GetXDocument(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;part &lt;span style="color: blue"&gt;As &lt;/span&gt;OpenXmlPart) &lt;span style="color: blue"&gt;As &lt;/span&gt;XDocument
        &lt;span style="color: blue"&gt;Dim &lt;/span&gt;xdoc &lt;span style="color: blue"&gt;As &lt;/span&gt;XDocument

        &lt;span style="color: blue"&gt;Using &lt;/span&gt;sr &lt;span style="color: blue"&gt;As New &lt;/span&gt;StreamReader(part.GetStream())
            xdoc = XDocument.Load(XmlReader.Create(sr))
            sr.Close()
        &lt;span style="color: blue"&gt;End Using

        Return &lt;/span&gt;xdoc
    &lt;span style="color: blue"&gt;End Function
End Module&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Now we can go back to our main Module1 and add a the ParseOrderDocument method. Notice that I'm using the Extension method we created in the For Each part... loop to return the custom XML as an XDocument. Then I use the child axis property &amp;lt;OrderEntry&amp;gt; (displayed in IntelliSense as I type the query) to see if the element exists. Also notice that since I imported our XML namespace at the top of the file it will only return an &amp;lt;OrderEntry&amp;gt; element in that namespace. So we're safe not to clash with other custom XML that may be added to the document by other processes.&lt;/p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;pre class="code"&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
&lt;/span&gt;&lt;span style="color: green"&gt;''' Attempts to parse the word document for order data and returns an order
'''  object with all the required. The document must have a customXML part 
'''  that adheres to the OrderEntry.xsd
''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
&lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;docStream&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;The document to parse&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
&lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;The order data contained in the document&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/returns&amp;gt;
&lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;Function &lt;/span&gt;ParseOrderDocument(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;docStream &lt;span style="color: blue"&gt;As &lt;/span&gt;Stream) &lt;span style="color: blue"&gt;As &lt;/span&gt;DocumentOrderData
    &lt;span style="color: blue"&gt;Dim &lt;/span&gt;orderData &lt;span style="color: blue"&gt;As &lt;/span&gt;DocumentOrderData = &lt;span style="color: blue"&gt;Nothing

    Try
        &lt;/span&gt;&lt;span style="color: green"&gt;'Use the Open XML SDK to open the document and access parts easily
        &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;wordDoc = WordprocessingDocument.Open(docStream, &lt;span style="color: blue"&gt;False&lt;/span&gt;)

        &lt;span style="color: blue"&gt;Using &lt;/span&gt;wordDoc
            &lt;span style="color: green"&gt;'Get the main document part (document.xml)
            &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;mainPart = wordDoc.MainDocumentPart
            &lt;span style="color: blue"&gt;Dim &lt;/span&gt;docXML &lt;span style="color: blue"&gt;As &lt;/span&gt;XElement = &lt;span style="color: blue"&gt;Nothing

            &lt;/span&gt;&lt;span style="color: green"&gt;'Find the order data custom XML part
            &lt;/span&gt;&lt;span style="color: blue"&gt;For Each &lt;/span&gt;part &lt;span style="color: blue"&gt;In &lt;/span&gt;mainPart.CustomXmlParts
                docXML = part.GetXDocument.&lt;span style="color: #6464b9"&gt;&amp;lt;&lt;/span&gt;OrderEntry&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;.FirstOrDefault()
                &lt;span style="color: blue"&gt;If &lt;/span&gt;docXML &lt;span style="color: blue"&gt;IsNot Nothing Then
                    Exit For
                End If
            Next

            If &lt;/span&gt;docXML &lt;span style="color: blue"&gt;Is Nothing Then
                Throw New &lt;/span&gt;InvalidOperationException(&lt;span style="color: #a31515"&gt;&amp;quot;This document does not contain order entry data.&amp;quot;&lt;/span&gt;)
            &lt;span style="color: blue"&gt;End If

            &lt;/span&gt;&lt;span style="color: green"&gt;'Grab the order data fields from the XML 
            &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;customerID = docXML.&lt;span style="color: #6464b9"&gt;&amp;lt;&lt;/span&gt;CustomerID&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;.Value.Trim()
            &lt;span style="color: blue"&gt;Dim &lt;/span&gt;orderDate = docXML.&lt;span style="color: #6464b9"&gt;&amp;lt;&lt;/span&gt;OrderDate&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;.Value.Trim()
            &lt;span style="color: blue"&gt;Dim &lt;/span&gt;shipper = docXML.&lt;span style="color: #6464b9"&gt;&amp;lt;&lt;/span&gt;Shipper&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;.Value.Trim()

            &lt;span style="color: blue"&gt;If &lt;/span&gt;customerID &amp;lt;&amp;gt; &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;AndAlso &lt;/span&gt;IsDate(orderDate) &lt;span style="color: blue"&gt;Then
                &lt;/span&gt;&lt;span style="color: green"&gt;'Create and fill the DocumentOrderData  
                &lt;/span&gt;orderData = &lt;span style="color: blue"&gt;New &lt;/span&gt;DocumentOrderData(customerID, &lt;span style="color: blue"&gt;CDate&lt;/span&gt;(orderDate), shipper)

                &lt;span style="color: blue"&gt;For Each &lt;/span&gt;item &lt;span style="color: blue"&gt;In &lt;/span&gt;docXML.&lt;span style="color: #6464b9"&gt;&amp;lt;&lt;/span&gt;OrderDetails&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;.&lt;span style="color: #6464b9"&gt;&amp;lt;&lt;/span&gt;OrderDetail&lt;span style="color: #6464b9"&gt;&amp;gt;
                    &lt;/span&gt;&lt;span style="color: green"&gt;'Grab order details data fields
                    &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;product = item.&lt;span style="color: #6464b9"&gt;&amp;lt;&lt;/span&gt;ProductName&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;.Value.Trim()
                    &lt;span style="color: blue"&gt;Dim &lt;/span&gt;quantity = item.&lt;span style="color: #6464b9"&gt;&amp;lt;&lt;/span&gt;Quantity&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;.Value.Trim()

                    &lt;span style="color: blue"&gt;If &lt;/span&gt;product &amp;lt;&amp;gt; &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;AndAlso &lt;/span&gt;IsNumeric(quantity) &lt;span style="color: blue"&gt;Then
                        &lt;/span&gt;&lt;span style="color: green"&gt;'Add a new DocumentOrderData.Detail for each product found
                        &lt;/span&gt;orderData.Details.Add(&lt;span style="color: blue"&gt;New &lt;/span&gt;DocumentOrderData.Detail(product, &lt;span style="color: blue"&gt;CShort&lt;/span&gt;(quantity)))
                    &lt;span style="color: blue"&gt;End If

                Next
            End If
            &lt;/span&gt;wordDoc.Close()
        &lt;span style="color: blue"&gt;End Using

    Catch &lt;/span&gt;ex &lt;span style="color: blue"&gt;As &lt;/span&gt;Exception
        &lt;span style="color: blue"&gt;Throw New &lt;/span&gt;InvalidOperationException(&lt;span style="color: #a31515"&gt;&amp;quot;Could not process this document.&amp;quot;&lt;/span&gt;, ex)
    &lt;span style="color: blue"&gt;End Try

    Return &lt;/span&gt;orderData
&lt;span style="color: blue"&gt;End Function&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;Updating the Database through the Data Service&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that we have our document parsed we're just left with adding the data through our data service.&amp;#160; What we need to do is query the reference data (entities) that we'll need to properly associate on our Order. For instance Order will need a reference to the Customer, the Employee and the Shipper. Then each Order_Detail will need a reference to the Product entity. Notice that we're passing the employee email address into this method so that we can associate the sales rep with the order. &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/03/oba-part-1-exposing-line-of-business-data.aspx" target="_blank"&gt;If you recall we had to add this field&lt;/a&gt; to the Customer and Employee tables in Northwind. (For this test program I'm hard-coding the value but later we'll get this information from the Outlook client when it submits the order to SharePoint.)&lt;/p&gt;

&lt;p&gt;Once we have these entities queried and returned from the service we can link them up properly and add our new Order and Order_Details to the data service. For more information on updating data and setting proper linkage to entities returned from an ADO.NET data service &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/01/20/ado-net-data-services-enforcing-fk-associations-and-a-fix-for-deleting-entities.aspx" target="_blank"&gt;read this post&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/phaniraj/archive/2008/07/02/working-with-relations-in-ado-net-data-services-beta-1.aspx" target="_blank"&gt;this one&lt;/a&gt;. &lt;/p&gt;

&lt;pre class="code"&gt;    &lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' Adds a new order through the ADO.NET Data service and sets up all the required
    ''' associations to related entities.
    ''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;docData&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;The order data&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;employeeEmail&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;EmailAddress of sales representitve&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
    &lt;/span&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;AddNewOrder(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;docData &lt;span style="color: blue"&gt;As &lt;/span&gt;DocumentOrderData, &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;employeeEmail &lt;span style="color: blue"&gt;As String&lt;/span&gt;)

        &lt;span style="color: blue"&gt;Dim &lt;/span&gt;ctx &lt;span style="color: blue"&gt;As New &lt;/span&gt;NorthwindEntities(&lt;span style="color: blue"&gt;New &lt;/span&gt;Uri(&lt;span style="color: #a31515"&gt;&amp;quot;http://localhost:1234/Northwind.svc/&amp;quot;&lt;/span&gt;))
      &lt;span style="color: blue"&gt;  Dim &lt;/span&gt;cust &lt;span style="color: blue"&gt;As &lt;/span&gt;Customer
        &lt;span style="color: blue"&gt;Try
            &lt;/span&gt;&lt;span style="color: green"&gt;'Try to retrieve the customer
            &lt;/span&gt;cust = (&lt;span style="color: blue"&gt;From &lt;/span&gt;c &lt;span style="color: blue"&gt;In &lt;/span&gt;ctx.Customers _
                     &lt;span style="color: blue"&gt;Where &lt;/span&gt;c.CustomerID = docData.CustomerID).FirstOrDefault()

        &lt;span style="color: blue"&gt;Catch &lt;/span&gt;ex &lt;span style="color: blue"&gt;As &lt;/span&gt;Exception
            &lt;span style="color: blue"&gt;Throw New &lt;/span&gt;InvalidOperationException(&lt;span style="color: #a31515"&gt;&amp;quot;Invalid customer ID.&amp;quot;&lt;/span&gt;)&lt;span style="color: blue"&gt;
        End Try

        If &lt;/span&gt;cust &lt;span style="color: blue"&gt;IsNot Nothing Then

            Dim &lt;/span&gt;ship = (&lt;span style="color: blue"&gt;From &lt;/span&gt;s &lt;span style="color: blue"&gt;In &lt;/span&gt;ctx.Shippers _
                        &lt;span style="color: blue"&gt;Where &lt;/span&gt;s.CompanyName = docData.Shipper).FirstOrDefault()

            &lt;span style="color: green"&gt;'Email Address will come from our Outlook client/sales person 
            &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;emp = (&lt;span style="color: blue"&gt;From &lt;/span&gt;e &lt;span style="color: blue"&gt;In &lt;/span&gt;ctx.Employees _
                       &lt;span style="color: blue"&gt;Where &lt;/span&gt;e.EmailAddress = employeeEmail).FirstOrDefault()

            &lt;span style="color: blue"&gt;Dim &lt;/span&gt;o &lt;span style="color: blue"&gt;As New &lt;/span&gt;Order()

            o.OrderDate = docData.OrderDate
            o.RequiredDate = Now.AddDays(2)
            o.ShipAddress = cust.Address
            o.ShipCity = cust.City
            o.ShipCountry = cust.Country
            o.ShipName = cust.ContactName
            o.ShipPostalCode = cust.PostalCode
            o.ShipRegion = cust.Region
            o.Freight = 25

            ctx.AddToOrders(o)

            o.Customer = cust
            ctx.SetLink(o, &lt;span style="color: #a31515"&gt;&amp;quot;Customer&amp;quot;&lt;/span&gt;, cust)

            &lt;span style="color: blue"&gt;If &lt;/span&gt;ship &lt;span style="color: blue"&gt;IsNot Nothing Then
                &lt;/span&gt;o.Shipper = ship
                ctx.SetLink(o, &lt;span style="color: #a31515"&gt;&amp;quot;Shipper&amp;quot;&lt;/span&gt;, ship)
            &lt;span style="color: blue"&gt;End If

            If &lt;/span&gt;emp &lt;span style="color: blue"&gt;IsNot Nothing Then
                &lt;/span&gt;o.Employee = emp
                ctx.SetLink(o, &lt;span style="color: #a31515"&gt;&amp;quot;Employee&amp;quot;&lt;/span&gt;, emp)
            &lt;span style="color: blue"&gt;End If

            &lt;/span&gt;o.Order_Details = &lt;span style="color: blue"&gt;New &lt;/span&gt;System.Collections.ObjectModel.Collection(&lt;span style="color: blue"&gt;Of &lt;/span&gt;Order_Detail)

            &lt;span style="color: blue"&gt;For Each &lt;/span&gt;item &lt;span style="color: blue"&gt;In &lt;/span&gt;docData.Details
                &lt;span style="color: blue"&gt;Dim &lt;/span&gt;productName = item.ProductName.ToLower()
                &lt;span style="color: blue"&gt;Dim &lt;/span&gt;product = (&lt;span style="color: blue"&gt;From &lt;/span&gt;p &lt;span style="color: blue"&gt;In &lt;/span&gt;ctx.Products _
                               &lt;span style="color: blue"&gt;Where &lt;/span&gt;p.ProductName.ToLower() = productName).FirstOrDefault()

                &lt;span style="color: blue"&gt;If &lt;/span&gt;product &lt;span style="color: blue"&gt;IsNot Nothing Then
                    &lt;/span&gt;&lt;span style="color: green"&gt;'Create a detail for each product being ordered
                    &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;detail &lt;span style="color: blue"&gt;As New &lt;/span&gt;Order_Detail()
                    o.Order_Details.Add(detail)

                    detail.Quantity = item.Quantity
                    detail.UnitPrice = &lt;span style="color: blue"&gt;If&lt;/span&gt;(product.UnitPrice.HasValue, _
                                          product.UnitPrice.Value, 1D)

                    ctx.AddToOrder_Details(detail)

                    detail.Product = product
                    ctx.SetLink(detail, &lt;span style="color: #a31515"&gt;&amp;quot;Product&amp;quot;&lt;/span&gt;, product)

                    detail.Order = o
                    ctx.SetLink(detail, &lt;span style="color: #a31515"&gt;&amp;quot;Order&amp;quot;&lt;/span&gt;, o)

                    ctx.AddLink(o, &lt;span style="color: #a31515"&gt;&amp;quot;Order_Details&amp;quot;&lt;/span&gt;, detail)
                &lt;span style="color: blue"&gt;End If
            Next
            &lt;/span&gt;&lt;span style="color: green"&gt;'Saving in Batch mode will update the data inside a database transaction
            'This will throw an exception if the service can't save the Order
            &lt;/span&gt;ctx.SaveChanges(Services.Client.SaveChangesOptions.Batch)
        &lt;span style="color: blue"&gt;End If
    End Sub
End Module&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;When we run this program we will see that Customer ALFKI now has a new Order and 4 Order Details entered into the database. Since we're sending the updates in Batch mode this will cause our order data to be properly wrapped in a database transaction.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart3ReadingDatafromWordDocuments_DE22/wordcc6_2.jpg"&gt;&lt;img height="509" alt="wordcc6" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart3ReadingDatafromWordDocuments_DE22/wordcc6_thumb.jpg" width="666" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Next post we'll talk about how we can create a SharePoint workflow to run this code when order documents are added to a SharePoint list. However, if SharePoint is not a requirement of your system (maybe you have no need to collaborate on documents or store this unstructured data) you could easily add this code directly to the &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/07/oba-part-2-building-and-outlook-client-against-lob-data.aspx" target="_blank"&gt;Outlook client we built in the previous post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I updated &lt;a href="http://code.msdn.microsoft.com/OBANorthwind" target="_blank"&gt;the sample on Code Gallery&lt;/a&gt; with this project so have a look. &lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9416665" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Article/default.aspx">Article</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/XML/default.aspx">XML</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Office/default.aspx">Office</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Data/default.aspx">Data</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/ADO.NET+Data+Services/default.aspx">ADO.NET Data Services</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/SharePoint/default.aspx">SharePoint</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/OBA/default.aspx">OBA</category></item><item><title>OBA Part 2 - Building an Outlook Client against LOB Data</title><link>http://blogs.msdn.com/bethmassi/archive/2009/02/07/oba-part-2-building-and-outlook-client-against-lob-data.aspx</link><pubDate>Sun, 08 Feb 2009 01:36:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9405756</guid><dc:creator>Beth Massi</dc:creator><slash:comments>9</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9405756.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9405756</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9405756</wfw:comment><description>&lt;P&gt;In the last couple posts we've been talking about an &lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/02/02/building-an-office-business-application-for-techready-8.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2009/02/02/building-an-office-business-application-for-techready-8.aspx"&gt;Office Business Application (OBA) architecture for the new Northwind Traders&lt;/A&gt; and &lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/02/03/oba-part-1-exposing-line-of-business-data.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2009/02/03/oba-part-1-exposing-line-of-business-data.aspx"&gt;how to expose line-of-business (LOB) data&lt;/A&gt;, in our case the Northwind SQL database, &lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/01/09/using-ado-net-data-services.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2009/01/09/using-ado-net-data-services.aspx"&gt;using ADO.NET Data Services&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;&lt;IMG style="MARGIN: 0px 5px 0px 0px" height=352 alt=OutlookOBAdiagram src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookOBAdiagram_thumb_1.jpg" width=178 align=left border=0 mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookOBAdiagram_thumb_1.jpg"&gt;Today we're going to talk about how to build an Outlook Add-In that pulls the order history from the database through our data service when a customer email arrives in the inbox of our sales reps. This allows the sales reps to easily communicate current order status and product inventory with the customer without having to open up another program. That's the idea -- we're choosing to build a solution that is instantly familiar to our users since they already live in Outlook. &lt;/P&gt;
&lt;P&gt;We're going to display the order history and inventory information in a WPF control in an adjoining form region so that it displays on the email item itself. It will display when the email opens or is displayed in the preview pane. We could have used a Windows Forms control but WPF is going to look a lot better. We want to match the blue color gradients that Outlook uses so that the control looks built in. Using WPF in Office solutions built with Visual Studio is really easy so let's get started.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The Outlook Add-in Project&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;I'm going to build upon the Visual Studio Solution that we started in the previous post when we built the data service. This solution also contains a database project that I'm using to keep the change scripts organized. If you recall we needed to add an EmailAddress field to Customers and Employees tables in Northwind. We also added some Customer and Employee data that specify the email addresses we are going to use to test the sample.&lt;/P&gt;
&lt;P&gt;So just add a new project to the solution and select Office 2007 Outlook Add-In which is available in Visual Studio 2008 Professional and higher: &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient1_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient1_2.jpg"&gt;&lt;IMG height=368 alt=OutlookClient1 src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient1_thumb.jpg" width=691 border=0 mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient1_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Next we need to add a service reference to the data service &lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/01/09/using-ado-net-data-services.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2009/01/09/using-ado-net-data-services.aspx"&gt;like I showed here&lt;/A&gt; when building a simple console app client. Right-click on the project, select Add Service Reference, click the "Discover" button and name the reference NorthwindService. This will generate the proxy code and entity types used by the data service. It will also add a reference to the System.Data.Services.Client assembly.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Building the Outlook Form Region&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Now we'll add the Outlook Form region. Add new item to the project and select Outlook Form Region and name it EmailForm. When you click "Add", a dialog will appear that will ask you if you want to design a new region yourself or if you want to import one. Select "Design a new form region" and click Next. Then it asks you how you want the region to appear, whether it should be on it's own tab or adjoining or a complete replacement. We want to display the order and product information below the customer emails so select adjoining.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient2_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient2_2.jpg"&gt;&lt;IMG height=300 alt=OutlookClient2 src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient2_thumb.jpg" width=345 align=left border=0 mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient2_thumb.jpg"&gt;&lt;/A&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient3_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient3_2.jpg"&gt;&lt;IMG height=300 alt=OutlookClient3 src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient3_thumb.jpg" width=346 border=0 mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient3_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;When we click next we are asked what the Name of the adjoining region should be -- this is displayed in the separator between the email and our control -- so I have specified "Order History". And since we only want to display order history on emails in read mode, uncheck the compose mode checkbox. Finally we are asked which message classes will display the form region. Keep the default selection which specifies all messages. Click finish and the designer will display an empty Windows Forms user control. &lt;/P&gt;
&lt;P&gt;Let's test this out real quick, even though we haven't written any code. Set the Outlook client as the Startup Project and hit F5 and you will see Outlook open. Select any message in your inbox and notice that below the email you will see a blank form region labeled "Order History". However we don't want the form region to display for every email we get, only the Northwind customers. So what we'll do is write some code that checks the Northwind database for any email addresses coming into the inbox to see if they match our customers and only display the region in that case. Back on the EmailForm user control right-click and view code, you will see the following template already set up for you:&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Imports &lt;/SPAN&gt;Microsoft.Office.Tools.Outlook

&lt;SPAN style="COLOR: blue"&gt;Public Class &lt;/SPAN&gt;EmailForm
&lt;SPAN style="COLOR: blue"&gt;#Region &lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"Form Region Factory"
    &lt;/SPAN&gt;&amp;lt;Microsoft.Office.Tools.Outlook.FormRegionMessageClass(FormRegionMessageClassAttribute.Note)&amp;gt; _
    &amp;lt;Microsoft.Office.Tools.Outlook.FormRegionName(&lt;SPAN style="COLOR: #a31515"&gt;"NorthwindOutlookClient.EmailForm"&lt;/SPAN&gt;)&amp;gt; _
    &lt;SPAN style="COLOR: blue"&gt;Partial Public Class &lt;/SPAN&gt;EmailFormFactory

        &lt;SPAN style="COLOR: green"&gt;' Occurs before the form region is initialized.
        ' To prevent the form region from appearing, set e.Cancel to true.
        ' Use e.OutlookItem to get a reference to the current Outlook item.
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Private Sub &lt;/SPAN&gt;EmailFormFactory_FormRegionInitializing(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;sender &lt;SPAN style="COLOR: blue"&gt;As Object&lt;/SPAN&gt;, _
                                                     &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;e &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;FormRegionInitializingEventArgs) _
                                                     &lt;SPAN style="COLOR: blue"&gt;Handles Me&lt;/SPAN&gt;.FormRegionInitializing
        &lt;SPAN style="COLOR: blue"&gt;End Sub
    End Class
#End Region
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;'Occurs before the form region is displayed. 
    'Use Me.OutlookItem to get a reference to the current Outlook item.
    'Use Me.OutlookFormRegion to get a reference to the form region.
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Private Sub &lt;/SPAN&gt;EmailForm_FormRegionShowing(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;sender &lt;SPAN style="COLOR: blue"&gt;As Object&lt;/SPAN&gt;, _
                                      &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;e &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;System.EventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles MyBase&lt;/SPAN&gt;.FormRegionShowing
    &lt;SPAN style="COLOR: blue"&gt;End Sub

    &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;'Occurs when the form region is closed.   
    'Use Me.OutlookItem to get a reference to the current Outlook item.
    'Use Me.OutlookFormRegion to get a reference to the form region.
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Private Sub &lt;/SPAN&gt;EmailForm_FormRegionClosed(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;sender &lt;SPAN style="COLOR: blue"&gt;As Object&lt;/SPAN&gt;, _
                                     &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;e &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;System.EventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles MyBase&lt;/SPAN&gt;.FormRegionClosed
    &lt;SPAN style="COLOR: blue"&gt;End Sub
End Class&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;The EmailFormFactory nested class is what creates the EmailForm and it gives us a chance to cancel showing the region. Here's where we need to write some code that gets the email address from the mail item and checks the database through the data service. In the FormRegionShowing event handler of the EmailForm we will pull down the Order History based on the customer address along with the Order_Details and related Products. Since we're going to need to get the EmailAddress as well as connect to the same data service in both event handlers, a good place to write global code is in the ThisAddIn class which is automatically created for you when you create the Add-in project. &lt;/P&gt;
&lt;P&gt;Double-click on ThisAddIn in the Solution Explorer to open the code. You will see StartUp and ShutDown event handlers for the Add-In automatically generated for you. We don't need to add any code into these handlers. All we need to do is add a public property to the service reference for our data service as well as a function to extract the SMTP email address from the mail item. Note that I added an application setting to specify the location of the data service. During development this is going to be http://localhost:1234:/Northwind.svc but when we deploy the application we'll change it to the location of our production service:&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Imports &lt;/SPAN&gt;NorthwindOutlookClient.NorthwindService

&lt;SPAN style="COLOR: blue"&gt;Public Class &lt;/SPAN&gt;ThisAddIn

    &lt;SPAN style="COLOR: blue"&gt;Private &lt;/SPAN&gt;_ctx &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;NorthwindEntities
    &lt;SPAN style="COLOR: blue"&gt;Public ReadOnly Property &lt;/SPAN&gt;DataServiceContext() &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;NorthwindEntities
        &lt;SPAN style="COLOR: blue"&gt;Get
            If &lt;/SPAN&gt;_ctx &lt;SPAN style="COLOR: blue"&gt;Is Nothing Then
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;'Specify the Service URI in the app.config via project settings.
                &lt;/SPAN&gt;_ctx = &lt;SPAN style="COLOR: blue"&gt;New &lt;/SPAN&gt;NorthwindEntities(&lt;SPAN style="COLOR: blue"&gt;New &lt;/SPAN&gt;Uri(&lt;SPAN style="COLOR: blue"&gt;My&lt;/SPAN&gt;.Settings.ServiceURI))
            &lt;SPAN style="COLOR: blue"&gt;End If
            Return &lt;/SPAN&gt;_ctx
        &lt;SPAN style="COLOR: blue"&gt;End Get
    End Property

    &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;''' &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;''' Extracts the SMTP email address from the mail item.
    ''' &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;''' &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;param name="mailItem"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;the Outlook mail item&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;''' &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;returns&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;The SMTP email address, otherwise empty string&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;/returns&amp;gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;''' &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Public Function &lt;/SPAN&gt;GetEmailAddress(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;mailItem &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Outlook.MailItem) &lt;SPAN style="COLOR: blue"&gt;As String
        Dim &lt;/SPAN&gt;recip &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Outlook.Recipient
        &lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;exUser &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Outlook.ExchangeUser
        &lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;emailAddress &lt;SPAN style="COLOR: blue"&gt;As String &lt;/SPAN&gt;= &lt;SPAN style="COLOR: #a31515"&gt;""

        &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Try
            If &lt;/SPAN&gt;mailItem &lt;SPAN style="COLOR: blue"&gt;IsNot Nothing AndAlso &lt;/SPAN&gt;mailItem.SenderEmailType &lt;SPAN style="COLOR: blue"&gt;IsNot Nothing Then
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;''get SMTP Address for the sender of this email
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;If &lt;/SPAN&gt;mailItem.SenderEmailType.ToLower = &lt;SPAN style="COLOR: #a31515"&gt;"ex" &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Then
                    &lt;/SPAN&gt;recip = Globals.ThisAddIn.Application.GetNamespace(&lt;SPAN style="COLOR: #a31515"&gt;"MAPI"&lt;/SPAN&gt;) _
                            .CreateRecipient(mailItem.SenderEmailAddress)

                    exUser = recip.AddressEntry.GetExchangeUser()
                    emailAddress = exUser.PrimarySmtpAddress
                &lt;SPAN style="COLOR: blue"&gt;Else
                    &lt;/SPAN&gt;emailAddress = mailItem.SenderEmailAddress
                &lt;SPAN style="COLOR: blue"&gt;End If
            End If

        Catch &lt;/SPAN&gt;ex &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Exception
            emailAddress = &lt;SPAN style="COLOR: #a31515"&gt;""
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;End Try
        Return &lt;/SPAN&gt;emailAddress
    &lt;SPAN style="COLOR: blue"&gt;End Function

    Private Sub &lt;/SPAN&gt;ThisAddIn_Startup(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;sender &lt;SPAN style="COLOR: blue"&gt;As Object&lt;/SPAN&gt;, _
                                  &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;e &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;System.EventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles Me&lt;/SPAN&gt;.Startup
    &lt;SPAN style="COLOR: blue"&gt;End Sub

    Private Sub &lt;/SPAN&gt;ThisAddIn_Shutdown(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;sender &lt;SPAN style="COLOR: blue"&gt;As Object&lt;/SPAN&gt;, _
                                   &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;e &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;System.EventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles Me&lt;/SPAN&gt;.Shutdown
    &lt;SPAN style="COLOR: blue"&gt;End Sub
End Class&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Now back in the EmailFormFactory we can add this code to check if we should even be displaying the form region at all. If we don't want to show it, just set e.Cancel =True:&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: green"&gt;' Occurs before the form region is initialized.
' To prevent the form region from appearing, set e.Cancel to true.
' Use e.OutlookItem to get a reference to the current Outlook item.
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Private Sub &lt;/SPAN&gt;EmailFormFactory_FormRegionInitializing(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;sender &lt;SPAN style="COLOR: blue"&gt;As Object&lt;/SPAN&gt;, _
                                                    &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;e &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;FormRegionInitializingEventArgs) _
                                                    &lt;SPAN style="COLOR: blue"&gt;Handles Me&lt;/SPAN&gt;.FormRegionInitializing
    &lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;emailAddress &lt;SPAN style="COLOR: blue"&gt;As String &lt;/SPAN&gt;= &lt;SPAN style="COLOR: #a31515"&gt;""
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;ctx = NorthwindOutlookClient.Globals.ThisAddIn.DataServiceContext
    &lt;SPAN style="COLOR: blue"&gt;Try
        Dim &lt;/SPAN&gt;mailItem = &lt;SPAN style="COLOR: blue"&gt;TryCast&lt;/SPAN&gt;(e.OutlookItem, Outlook.MailItem)
        emailAddress = NorthwindOutlookClient.Globals.ThisAddIn.GetEmailAddress(mailItem)

        &lt;SPAN style="COLOR: blue"&gt;If &lt;/SPAN&gt;emailAddress &amp;lt;&amp;gt; &lt;SPAN style="COLOR: #a31515"&gt;"" &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Then
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;'Make sure the email address is actually in the database
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;customer = (&lt;SPAN style="COLOR: blue"&gt;From &lt;/SPAN&gt;c &lt;SPAN style="COLOR: blue"&gt;In &lt;/SPAN&gt;ctx.Customers _
                            &lt;SPAN style="COLOR: blue"&gt;Where &lt;/SPAN&gt;c.EmailAddress = emailAddress).FirstOrDefault()

            &lt;SPAN style="COLOR: blue"&gt;If &lt;/SPAN&gt;customer &lt;SPAN style="COLOR: blue"&gt;Is Nothing Then
                &lt;/SPAN&gt;emailAddress = &lt;SPAN style="COLOR: #a31515"&gt;""
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;End If
        End If
    Catch &lt;/SPAN&gt;ex &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Exception
        &lt;SPAN style="COLOR: green"&gt;'TODO: Error logging
        &lt;/SPAN&gt;emailAddress = &lt;SPAN style="COLOR: #a31515"&gt;""
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;End Try

    &lt;/SPAN&gt;e.Cancel = (emailAddress = &lt;SPAN style="COLOR: #a31515"&gt;""&lt;/SPAN&gt;)
&lt;SPAN style="COLOR: blue"&gt;End Sub&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;Note that a service call could experience unexpected delays depending on where the data service is located. We may want to consider just displaying the form region and writing the calls to the service asynchronously. This is possible using the &lt;A href="http://msdn.microsoft.com/en-us/library/cc907912.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/cc907912.aspx"&gt;ADO.NET Data Services client as described in this article&lt;/A&gt;. For now, we'll keep this OBA sample simple and assume that the data service is located somewhere on our intranet.&lt;/P&gt;
&lt;P&gt;Now that we have this code in place we can write the code that will specify a LINQ query to retrieve the order history in the EmailForm's FormRegionShowing handler. Notice I'm using the ".Expand" syntax in the query to pull in the related entities on the Order. Then I'm pulling the Product entity down for each of the Order_Detail entities so I can display inventory information. (We may want to consider only pulling orders within a date range for better scalability but here I'm pulling all of them down for the specified customer for simplicity.) &lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: green"&gt;'Occurs before the form region is displayed. 
'Use Me.OutlookItem to get a reference to the current Outlook item.
'Use Me.OutlookFormRegion to get a reference to the form region.
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Private Sub &lt;/SPAN&gt;EmailForm_FormRegionShowing(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;sender &lt;SPAN style="COLOR: blue"&gt;As Object&lt;/SPAN&gt;, _
                &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;e &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;System.EventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles MyBase&lt;/SPAN&gt;.FormRegionShowing

    &lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;emailAddress &lt;SPAN style="COLOR: blue"&gt;As String &lt;/SPAN&gt;= &lt;SPAN style="COLOR: #a31515"&gt;""
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;ctx = NorthwindOutlookClient.Globals.ThisAddIn.DataServiceContext
    &lt;SPAN style="COLOR: blue"&gt;Try
        Dim &lt;/SPAN&gt;mailItem = &lt;SPAN style="COLOR: blue"&gt;TryCast&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.OutlookItem, Outlook.MailItem)
        emailAddress = NorthwindOutlookClient.Globals.ThisAddIn.GetEmailAddress(mailItem)

        &lt;SPAN style="COLOR: blue"&gt;If &lt;/SPAN&gt;emailAddress &amp;lt;&amp;gt; &lt;SPAN style="COLOR: #a31515"&gt;"" &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Then
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;'pull the order history from the database
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;customerOrders = &lt;SPAN style="COLOR: blue"&gt;From &lt;/SPAN&gt;o &lt;SPAN style="COLOR: blue"&gt;In &lt;/SPAN&gt;ctx.Orders.Expand(&lt;SPAN style="COLOR: #a31515"&gt;"Order_Details"&lt;/SPAN&gt;).Expand(&lt;SPAN style="COLOR: #a31515"&gt;"Customer"&lt;/SPAN&gt;) _
                              &lt;SPAN style="COLOR: blue"&gt;Where &lt;/SPAN&gt;o.Customer.EmailAddress = emailAddress _
                              &lt;SPAN style="COLOR: blue"&gt;Order By &lt;/SPAN&gt;o.OrderDate &lt;SPAN style="COLOR: blue"&gt;Descending

            For Each &lt;/SPAN&gt;order &lt;SPAN style="COLOR: blue"&gt;In &lt;/SPAN&gt;customerOrders
                &lt;SPAN style="COLOR: blue"&gt;For Each &lt;/SPAN&gt;detail &lt;SPAN style="COLOR: blue"&gt;In &lt;/SPAN&gt;order.Order_Details
                    ctx.LoadProperty(detail, &lt;SPAN style="COLOR: #a31515"&gt;"Product"&lt;/SPAN&gt;)
                &lt;SPAN style="COLOR: blue"&gt;Next
            Next

            Dim &lt;/SPAN&gt;ordersList &lt;SPAN style="COLOR: blue"&gt;As New &lt;/SPAN&gt;List(&lt;SPAN style="COLOR: blue"&gt;Of &lt;/SPAN&gt;Order)(customerOrders)
            &lt;SPAN style="COLOR: green"&gt;'TODO: Set this ordersList as the DataContext of our WPF user control

        &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;End If
    Catch &lt;/SPAN&gt;ex &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Exception
        &lt;SPAN style="COLOR: green"&gt;'Could not connect to the service
        'TODO: Error logging
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;End Try
End Sub&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;You also should notice that we still need to pass this list of Order entities that were returned from the data service into our WPF control -- but first we need to create it!&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Building the WPF User Control&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;So let's add a new WPF User control via Add New Item (listed under WPF) -- I named it OrderHistory. This will show the WPF designer. The WPF User Control simply specifies just the UI in XAML of what the control should look like and sets up the data binding to the properties on our entities. &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient4_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient4_2.jpg"&gt;&lt;IMG height=352 alt=OutlookClient4 src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient4_thumb.jpg" width=636 border=0 mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient4_thumb.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Here we've set up two ListViews that display Order and Order_Details and below that the Product inventory information along with an &lt;A class="" href="http://msdn.microsoft.com/en-us/library/cc165603.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/cc165603.aspx"&gt;Image Control&lt;/A&gt; showing off the new Northwind logo. This control is really easy to data bind because of how the entity associations are specified in our data model. Order has Order_Details collection and Order_Detail has a Product reference. When the WPF User Control's DataContext property is set to the list of Orders, the data binding will take care of displaying the related data properly. Here's how we set up the data bound controls (styles omitted for clarity):&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Class&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="OrderHistory"
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;x&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="300" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="541" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="OrderList" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Grid.IsSharedSizeScope&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="True"&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl.Resources&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Style ...&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: #a31515"&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl.Resources&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid.RowDefinitions&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;RowDefinition &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="120" /&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;RowDefinition &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="160*" /&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid.RowDefinitions&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
       
&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;IsSynchronizedWithCurrentItem&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="True" 
          &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;ItemsSource&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;}" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="ListViewOrder" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0,0,0,6" 
          &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;ListViewStyle&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;}"&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.View&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
        
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;ColumnHeaderContainerStyle&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;ColumnHeaderStyle&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;}"&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: red"&gt;DisplayMemberBinding&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Path&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;STRONG&gt;=ShipName}&lt;/STRONG&gt;" 
                            &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="200"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Ship to&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: red"&gt;DisplayMemberBinding&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=OrderDate, &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;StringFormat&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;STRONG&gt;='d'}&lt;/STRONG&gt;" 
                            &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="100"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Order Date&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: red"&gt;DisplayMemberBinding&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=ShippedDate, &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;StringFormat&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;STRONG&gt;='d'}&lt;/STRONG&gt;" 
                            &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="100"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Ship Date&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: red"&gt;DisplayMemberBinding&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=OrderTotal, &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;StringFormat&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;STRONG&gt;='c2'}&lt;/STRONG&gt;" 
                            &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="100"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Order Total&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.View&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Grid.Row&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="1" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="DetailsGrid" &lt;BR&gt;          &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: red"&gt;DataContext&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Path&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;STRONG&gt;=Order_Details}"&lt;/STRONG&gt;&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: red"&gt;ItemsSource&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;STRONG&gt;}"&lt;/STRONG&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Style&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;ListViewStyle&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;}"
                  &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;IsSynchronizedWithCurrentItem&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="True" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="ListViewDetails" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0,0,0,81"&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.View&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
                &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;ColumnHeaderContainerStyle&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StaticResource &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;ColumnHeaderStyle&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;}"&amp;gt;
                    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Header&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Product" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="300" 
                                    &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: red"&gt;DisplayMemberBinding&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Path&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;STRONG&gt;=Product.ProductName}"&lt;/STRONG&gt; /&amp;gt;
                    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Header&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Quantity" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="100" 
                                    &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: red"&gt;DisplayMemberBinding&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=Quantity, &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;StringFormat&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;STRONG&gt;='n0'}&lt;/STRONG&gt;" /&amp;gt;
                    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridViewColumn &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Header&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Unit Price" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="100" 
                                    &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: red"&gt;DisplayMemberBinding&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Path&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=UnitPrice, &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;StringFormat&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;STRONG&gt;='c2'}&lt;/STRONG&gt;" /&amp;gt;
                &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
            &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView.View&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListView&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Image &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="75" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;HorizontalAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Right" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Image1" 
               &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Stretch&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="None" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;VerticalAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Bottom" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="75" 
               &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Source&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="northwindlogo75.gif" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;SnapsToDevicePixels&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="True" 
               &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;StretchDirection&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="DownOnly" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;MinHeight&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="75" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;MinWidth&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="75" 
               &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;MaxHeight&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="75" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;MaxWidth&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="75" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;ClipToBounds&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="True" /&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StackPanel &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="75" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="StackPanel1" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;VerticalAlignment&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Bottom" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Margin&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="0,0,81,0"&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="25" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="txtProductName" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Auto"
                       &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: red"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Path&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;=Product.ProductName, 
                                      &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;StringFormat&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=Inventory &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;information for &lt;/SPAN&gt;\&lt;SPAN style="COLOR: blue"&gt;{&lt;/SPAN&gt;0\&lt;/STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;STRONG&gt;}}" &lt;/STRONG&gt;/&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="25" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="txtUnitsInStock" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Auto" 
                       &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: red"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Path&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;=Product.UnitsInStock, 
                                      &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;StringFormat&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=Units &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;in stock&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;: &lt;/SPAN&gt;\&lt;SPAN style="COLOR: blue"&gt;{&lt;/SPAN&gt;0&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;n0&lt;/SPAN&gt;\&lt;/STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;STRONG&gt;}}"&lt;/STRONG&gt; /&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TextBlock &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Height&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="25" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="txtUnitsOnOrder" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Width&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Auto" 
                       &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: red"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="{&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Binding &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Path&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;=Product.UnitsOnOrder, 
                                      &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;StringFormat&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=Units &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;on order&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;: &lt;/SPAN&gt;\&lt;SPAN style="COLOR: blue"&gt;{&lt;/SPAN&gt;0&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;n0&lt;/SPAN&gt;\&lt;/STRONG&gt;&lt;SPAN style="COLOR: blue"&gt;&lt;STRONG&gt;}}&lt;/STRONG&gt;"/&amp;gt;
        &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;StackPanel&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Grid&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;UserControl&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;Notice that there is a field I'm binding to called OrderTotal on the Order entity however if you go back to the data model (Northwind.edmx in the NorthwindService project) you won't see this field coming from the database. That's because it's a calculated property on the Order entity on the client. You can extend the entities on the client using Partial Classes. All you have to do is right click on the project and select Add--&amp;gt;Class, call it Order, and then make sure you specify the proper namespace of the service reference:&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Imports &lt;/SPAN&gt;NorthwindOutlookClient.NorthwindService

&lt;SPAN style="COLOR: blue"&gt;Namespace &lt;/SPAN&gt;NorthwindService

    &lt;SPAN style="COLOR: blue"&gt;Partial Public Class &lt;/SPAN&gt;Order

        &lt;SPAN style="COLOR: blue"&gt;Private &lt;/SPAN&gt;_total &lt;SPAN style="COLOR: blue"&gt;As Decimal &lt;/SPAN&gt;= 0
        &lt;SPAN style="COLOR: blue"&gt;Public ReadOnly Property &lt;/SPAN&gt;OrderTotal() &lt;SPAN style="COLOR: blue"&gt;As Decimal
            Get
                If &lt;/SPAN&gt;_total = 0 &lt;SPAN style="COLOR: blue"&gt;Then&lt;/SPAN&gt;
                    _total = &lt;SPAN style="COLOR: blue"&gt;Aggregate&lt;/SPAN&gt; detail &lt;SPAN style="COLOR: blue"&gt;In Me&lt;/SPAN&gt;.Order_Details _
                                &lt;SPAN style="COLOR: blue"&gt;Into&lt;/SPAN&gt; Sum(detail.Quantity * detail.UnitPrice)&lt;SPAN style="COLOR: blue"&gt;                    
                End If
                Return &lt;/SPAN&gt;_total
            &lt;SPAN style="COLOR: blue"&gt;End Get
        End Property
    End Class

End Namespace&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Now that we have our WPF control all designed we are ready to add it to our form region. EmailForm is a Windows Forms user control so in order to add the WPF user control we need to first add an ElementHost control. This is found in the WPF Interoperability Tab on your toolbox. When you drop this control onto the designer you can immediately select the WPF user control to display, in our case it shows the OrderHistory control we just designed (if you don't see it, build the project first).&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient5_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient5_2.jpg"&gt;&lt;IMG height=338 alt=OutlookClient5 src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient5_thumb.jpg" width=709 border=0 mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient5_thumb.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;I also set it to dock in the parent container so it takes up the entire region and set the font of the EmailForm region to Calibri 11. Lastly we can add the line of code back in our EmailForm_FormRegionShowing handler to set the list of Orders we returned from our data service to the DataContext of the WPF user control:&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;ordersList &lt;SPAN style="COLOR: blue"&gt;As New &lt;/SPAN&gt;List(&lt;SPAN style="COLOR: blue"&gt;Of &lt;/SPAN&gt;Order)(customerOrders)
&lt;SPAN style="COLOR: green"&gt;'Set this ordersList as the DataContext of our WPF user control
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Me&lt;/SPAN&gt;.OrderHistory1.DataContext = ordersList&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;That should do it! To test this you need to make sure the email address you'll be using is in the database so you'll have to add some test data. When we run it we should see the adjoining form region at the bottom of our customer emails (click to enlarge):&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient6_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient6_2.jpg"&gt;&lt;IMG height=444 alt=OutlookClient6 src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient6_thumb.jpg" width=681 border=0 mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart2BuildingtheOutlookAddIn_8AC8/OutlookClient6_thumb.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;One tip to remove the Outlook Add-in when you're done debugging is to select Build --&amp;gt; Clean Solution menu item in Visual Studio to unregister the Add-In. &lt;/P&gt;
&lt;P&gt;I've &lt;A href="http://code.msdn.microsoft.com/OBANorthwind/" target=_blank mce_href="http://code.msdn.microsoft.com/OBANorthwind/"&gt;uploaded the code that we've talked about so far in this series to Code Gallery&lt;/A&gt; so have a look. I'll continue adding releases to this as we build the other pieces of the OBA. Next post I'll show how we can create a purchase order in Word 2007 and use that to automatically feed Order data into the Northwind database.&lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9405756" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Article/default.aspx">Article</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Office/default.aspx">Office</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/ADO.NET+Data+Services/default.aspx">ADO.NET Data Services</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VSTO/default.aspx">VSTO</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/OBA/default.aspx">OBA</category></item><item><title>OBA Part 1 - Exposing Line-of-Business Data</title><link>http://blogs.msdn.com/bethmassi/archive/2009/02/03/oba-part-1-exposing-line-of-business-data.aspx</link><pubDate>Wed, 04 Feb 2009 01:23:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9393912</guid><dc:creator>Beth Massi</dc:creator><slash:comments>11</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9393912.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9393912</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9393912</wfw:comment><description>&lt;p&gt;Last post I talked about the &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/02/02/building-an-office-business-application-for-techready-8.aspx" target="_blank"&gt;high-level architecture of our &lt;strong&gt;O&lt;/strong&gt;ffice &lt;strong&gt;B&lt;/strong&gt;usiness &lt;strong&gt;A&lt;/strong&gt;pplication&lt;/a&gt; for the new Northwind Traders. There are a lot of different architecture options to consider when building an OBA. OBA is all about using Microsoft Office with your Line of Business (LOB) data. Whether that involves using SharePoint as well depends on the application. Since we wanted to store the unstructured data (the Northwind customer P.O.)&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart1ExposingLineofBusinessData_8D7A/OBAdiagram_2.jpg"&gt;&lt;img style="margin: 5px 10px 0px 0px" height="159" alt="OBAdiagram" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart1ExposingLineofBusinessData_8D7A/OBAdiagram_thumb.jpg" width="156" align="left" border="0" /&gt;&lt;/a&gt; SharePoint is a good fit here.&lt;/p&gt;  &lt;p&gt;There are a lot of options when thinking about how to expose your LOB data. For instance, you may already have a service oriented architecture at the enterprise that exposes data contracts and processes that you can consume from Office clients. Or maybe you have a small business and have decided to expose &lt;font color="#ff0000"&gt;&lt;font color="#000000"&gt;&lt;a href="http://msdn.microsoft.com/en-us/vbasic/cc138242.aspx" target="_blank"&gt;a simple service that returns and consumes n-tier DataSets&lt;/a&gt;&lt;/font&gt; &lt;/font&gt;directly. Or you already have a custom LOB data entry system using custom business objects and you want to reuse the business layer in the Office client. OBA doesn't dictate &lt;em&gt;how &lt;/em&gt;you expose this data. Because you can consume data in Office clients the same way you do in Windows apps the same types of decisions need to be made. &lt;/p&gt;  &lt;p&gt;When we sat down to write the new Northwind Traders application we thought about how our data would need to behave and what would be the best way for all the pieces to easily update and query the Northwind database. Because there was only going to be simple validations needed on the data and mostly CRUD operations we opted to expose an Entity Data Model via ADO.NET Data Services &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/01/09/using-ado-net-data-services.aspx" target="_blank"&gt;like I showed before&lt;/a&gt;. This allowed us to get a secure service up and running in minutes. &lt;/p&gt;  &lt;p&gt;We did make some minor changes to our old friend, the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=06616212-0356-46A0-8DA2-EEBC53A68034&amp;amp;displaylang=en" target="_blank"&gt;Northwind database&lt;/a&gt;. First, since we wanted to be able to look up order history for a customer when they emailed the sales reps, we needed to add an EmailAddress field to the Customers table (amazing that we didn't have that field before!). We also added it to the Employees table. &lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;ALTER TABLE &lt;/span&gt;dbo.Customers &lt;span style="color: blue"&gt;ADD
    &lt;/span&gt;EmailAddress &lt;span style="color: blue"&gt;varchar&lt;/span&gt;(50) &lt;span style="color: blue"&gt;NULL
&lt;/span&gt;GO
&lt;span style="color: blue"&gt;ALTER TABLE &lt;/span&gt;dbo.Employees &lt;span style="color: blue"&gt;ADD
    &lt;/span&gt;EmailAddress &lt;span style="color: blue"&gt;varchar&lt;/span&gt;(50) &lt;span style="color: blue"&gt;NULL
&lt;/span&gt;GO&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Then we populated the data with some customers and employees that were actually folks on our team because we need real email addresses to work with :-)&lt;/p&gt;

&lt;p&gt;Next I created a new ASP.NET Web Application and added an ADO.NET Data Service and an Entity Data Model just like how &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/01/09/using-ado-net-data-services.aspx" target="_blank"&gt;I showed in this post&lt;/a&gt;. (You will need &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=27673c47-b3b5-4c67-bd99-84e525b5ce61&amp;amp;displaylang=en" target="_blank"&gt;Visual Studio 2008 Service Pack 1&lt;/a&gt; in order to get these new item templates.) For testing we set the service to allow full access to all the entities in the model&amp;#160; -- we'll lock it down later. I also am passing detailed errors which we won't want to do once we're in production:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Public Class &lt;/span&gt;Northwind
    &lt;span style="color: blue"&gt;Inherits &lt;/span&gt;DataService(&lt;span style="color: blue"&gt;Of &lt;/span&gt;NorthwindEntities)

    &lt;span style="color: green"&gt;' This method is called only once to initialize service-wide policies.
    &lt;/span&gt;&lt;span style="color: blue"&gt;Public Shared Sub &lt;/span&gt;InitializeService(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;config &lt;span style="color: blue"&gt;As &lt;/span&gt;IDataServiceConfiguration)
        config.SetEntitySetAccessRule(&lt;span style="color: #a31515"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;, EntitySetRights.All)
        config.UseVerboseErrors = &lt;span style="color: blue"&gt;True
    End Sub&lt;br /&gt;End Class&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;One thing we did want to do is set up our data model so that it enforced constraints (i.e. there cannot be an Order without a Customer) but since some of our legacy data didn't specify all of these constraints we made the changes to the model instead, so that the integrity on all new data would be enforced through the service. This is often the case in projects, you cannot change the legacy databases but you still need to work with proper data models. So we changed the EDM so that all the entities were singular and not plural (Customer instead of Customers, Order instead of Orders, etc). We also changed the associations so that they were enforced and so that one to many collections were plural and the one-to-one were singular (i.e. Order has Order_Details collection and Order_Detail has Product reference). You can modify these from the Properties window of the &lt;font color="#ff0000"&gt;&lt;font color="#000000"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb738482.aspx" target="_blank"&gt;Entity Data Model Designer.&lt;/a&gt;&lt;/font&gt; &lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart1ExposingLineofBusinessData_8D7A/OBAedm_4.jpg"&gt;&lt;img height="475" alt="OBAedm" src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/OBAPart1ExposingLineofBusinessData_8D7A/OBAedm_thumb_1.jpg" width="641" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Once I have the model and the data service code set up we can hit F5 and navigate our browser to the Northwind.svc and test the call to pull up all the customers (i.e. http://localhost:1234/Northwind.svc/Customers) just like how &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/01/09/using-ado-net-data-services.aspx" target="_blank"&gt;I showed in this post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now that we have our data exposed as a data service we can build the Office clients to interact with it just like I showed before &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/01/22/ado-net-data-services-building-an-excel-client.aspx" target="_blank"&gt;here when we built a simple Excel client&lt;/a&gt;. Next post I'll show how we can use WPF controls in an Outlook Add-In in order to display the customer order history by querying the data through the data service. &lt;/p&gt;

&lt;p&gt;Until next time...&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9393912" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Article/default.aspx">Article</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Data/default.aspx">Data</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/ADO.NET+Data+Services/default.aspx">ADO.NET Data Services</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/OBA/default.aspx">OBA</category></item><item><title>Building an Office Business Application for TechReady 8</title><link>http://blogs.msdn.com/bethmassi/archive/2009/02/02/building-an-office-business-application-for-techready-8.aspx</link><pubDate>Tue, 03 Feb 2009 03:09:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9392479</guid><dc:creator>Beth Massi</dc:creator><slash:comments>18</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9392479.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9392479</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9392479</wfw:comment><description>&lt;P&gt;The last week I've been working with a couple teammates on an Office Business Application (OBA) demonstration we wanted to put together for TechReady 8. TechReady is an internal conference we deliver to the field employees. It's my first one and so far it's been pretty fun. This morning Scott Hanselman hosted an "UnKeynote" that showcased a lot of the new stuff coming in Visual Studio 2010 that I can't talk about yet but believe me it was cool. ;-)&lt;/P&gt;
&lt;P&gt;The application I helped build with Rachel and Mike on my team was a total blast. We wanted to demonstrate using Office as a client to Line-of-Business data as well as show some of the nifty features of SharePoint workflows. So we decided it was time to bring poor Northwind Traders into the 21st century. Here's what we came up with:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/BuildinganOfficeBusinessApplicationforTe_CD9B/OBANorthwind_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/BuildinganOfficeBusinessApplicationforTe_CD9B/OBANorthwind_2.jpg"&gt;&lt;IMG border=0 alt=OBANorthwind src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/BuildinganOfficeBusinessApplicationforTe_CD9B/OBANorthwind_thumb.jpg" width=683 height=484 mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/BuildinganOfficeBusinessApplicationforTe_CD9B/OBANorthwind_thumb.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;We needed a way to easily and securely expose our LOB data -- the Northwind database -- to the enterprise. So we created an entity data model against our SQL Server Northwind database and then exposed it using &lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/01/09/using-ado-net-data-services.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2009/01/09/using-ado-net-data-services.aspx"&gt;ADO.NET Data Services&lt;/A&gt; . The Northwind sales reps do all of their work in Outlook, communicating with our high-volume customers. So we built an Outlook Add-in that they can use to look up the customer order history from the database and easily work with purchase orders. The Add-in displays a form region with the customer order history in an adjoining area below when they open the email. &lt;/P&gt;
&lt;P&gt;The orders are then submitted to a SharePoint document library as Word 2007 documents with XML data specified via content controls. A SharePoint Workflow then shreds this document data (using VB XML literals support and the Open XML SDK) and passes it to the ADO.NET data Service which persists the data in the database. This was written as a SharePoint sequential workflow.&lt;/P&gt;
&lt;P&gt;We also built an Excel client for our shipping department to use that displays the orders that are ready to ship which allows them to update the ship date and save it back to through the data service. It also shows the products and quantities ordered in an Action Pane and does some data analysis using a pivot table and pie chart to show the breakdown of shipping cities and freight cost. We also used WPF user controls in the Outlook and Excel clients so that we could match the look-and-feel of Office. &lt;/P&gt;
&lt;P&gt;Finally we created a web part for the SharePoint site that displays key performance indicators like oversold products and our top customer sales.&lt;/P&gt;
&lt;P&gt;I have to say it was a very fun project to work on and I personally learned a lot about Excel and WPF as well as the OBA architecture. We spend about 3 days building this and I was pleasantly surprised how well the tools worked together. The pieces we built were predominantly in Visual Studio 2008 by Rachel and I and Mike handled the bleeding edge SharePoint parts.&lt;/P&gt;
&lt;P&gt;In the next few blog posts I'll go into the details of building WPF user controls in the Excel and Outlook clients and how we exposed a simple, clean data model against the not-so-clean Northwind database. I'll also show the technique of how we easily stripped the order data out of the Word 2007 documents. &lt;/P&gt;
&lt;P&gt;For now, some good links on OBA and VSTO development:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/vsto/dd164303.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/vsto/dd164303.aspx"&gt;Office Development Videos&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.com/vsto" target=_blank mce_href="http://msdn.com/vsto"&gt;Office Development with Visual Studio&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/01/22/ado-net-data-services-building-an-excel-client.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2009/01/22/ado-net-data-services-building-an-excel-client.aspx"&gt;ADO.NET Data Services - Building an Excel Client&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/vsto/" target=_blank mce_href="http://blogs.msdn.com/vsto/"&gt;Office Development with Visual Studio Team Blog&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Until next time....&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;UPDATE&lt;/STRONG&gt;&amp;nbsp;- Here is the full set of articles and code: &lt;A href="http://code.msdn.microsoft.com/OBANorthwind"&gt;http://code.msdn.microsoft.com/OBANorthwind&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9392479" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Visual+Basic/default.aspx">Visual Basic</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/DevCenter/default.aspx">DevCenter</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Office/default.aspx">Office</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Data/default.aspx">Data</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/ADO.NET+Data+Services/default.aspx">ADO.NET Data Services</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VS2010/default.aspx">VS2010</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VSTO/default.aspx">VSTO</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/SharePoint/default.aspx">SharePoint</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/OBA/default.aspx">OBA</category></item></channel></rss>