<?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 : Office</title><link>http://blogs.msdn.com/bethmassi/archive/tags/Office/default.aspx</link><description>Tags: Office</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>0</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>Setting up Windows 7 for Office &amp; SharePoint 2010 Beta Development</title><link>http://blogs.msdn.com/bethmassi/archive/2009/12/02/setting-up-windows-7-for-office-sharepoint-2010-beta-development.aspx</link><pubDate>Thu, 03 Dec 2009 03:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9931766</guid><dc:creator>Beth Massi</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9931766.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9931766</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9931766</wfw:comment><description>&lt;P&gt;So I decided to get my Windows 7 laptop installed with all the latest public Betas this week which includes Visual Studio Beta 2, SharePoint 2010 Beta and Office 2010 Beta. I had been using internal builds and thought it would be better to get in sync with everyone else in the community. I have to say there were a couple bumps that I experienced along the way that had me scratching my head and searching the web so I thought I’d consolidate all the resources I found and document the steps I did which resulted in a successful install. There is a lot of information out there depending on how you want to configure your system and I’m definitely not going to cover all the possibilities, I’m just going to focus on setting up a Windows 7 development environment and what worked for me in hopes of saving some time for other folks out there. &lt;STRONG&gt;As always, your mileage may vary.&lt;/STRONG&gt; &lt;/P&gt;
&lt;P&gt;&lt;EM&gt;NOTE: If you don’t plan on doing any SharePoint development then the install of Visual Studio and Office 2010 should be very smooth. I only experienced issues installing SharePoint 2010 Beta on my Windows 7 development machine. Also be aware that SharePoint 2010 Beta is supported on Windows 7 (and Vista) only for development purposes. So you will still need to have a testing environment built on Windows 2008 Server (or R2). For more information please see, &lt;A href="http://msdn.microsoft.com/en-us/library/ee554869(office.14).aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ee554869(office.14).aspx"&gt;Setting Up the Development Environment for SharePoint Server&lt;/A&gt; , &lt;A href="http://technet.microsoft.com/en-us/library/cc262957(office.14).aspx" target=_blank mce_href="http://technet.microsoft.com/en-us/library/cc262957(office.14).aspx"&gt;SharePoint Deployment&lt;/A&gt;, &lt;A href="http://technet.microsoft.com/en-us/library/cc262485(office.14).aspx" target=_blank mce_href="http://technet.microsoft.com/en-us/library/cc262485(office.14).aspx"&gt;Determine hardware and software requirements&lt;/A&gt; and &lt;A href="http://blogs.msdn.com/sharepointdeveloperdocs/archive/2009/11/20/sharepoint-2010-beta-release-known-issues.aspx" target=_blank mce_href="http://blogs.msdn.com/sharepointdeveloperdocs/archive/2009/11/20/sharepoint-2010-beta-release-known-issues.aspx"&gt;SharePoint 2010 Beta Release Known Issues&lt;/A&gt;.&lt;/EM&gt;&lt;/P&gt;
&lt;H4&gt;&lt;STRONG&gt;OS Requirements &amp;amp; Boot From VHD&lt;/STRONG&gt;&lt;/H4&gt;
&lt;P&gt;Before you attempt to set up a Windows 7 development environment, I &lt;STRONG&gt;highly &lt;/STRONG&gt;recommend booting from VHD. Do yourself a favor and create a Windows 7 bootable VHD so that if you mess up any part of an install you can simply delete it/roll back and start over. There’s a lot of information out there on how to do this but &lt;A href="http://blogs.technet.com/aviraj/archive/2009/01/18/windows-7-boot-from-vhd-first-impression-part-2.aspx" target=_blank mce_href="http://blogs.technet.com/aviraj/archive/2009/01/18/windows-7-boot-from-vhd-first-impression-part-2.aspx"&gt;I used these instructions to create a Win7 64-bit VHD&lt;/A&gt; via Hyper-V, sysprep-ed it, copied it to my local hard drive, and then used BCDEdit to add the VHD to my boot menu. &lt;/P&gt;
&lt;P&gt;Make sure you create a 64-bit Windows 7 Professional or higher edition with at least 4GB RAM if you’re going to do SharePoint development. You'll need Windows 7 Enterprise or Ultimate to boot from VHD.&lt;/P&gt;
&lt;H4&gt;&lt;STRONG&gt;What to Install - SharePoint Foundation or SharePoint Server?&lt;/STRONG&gt;&lt;/H4&gt;
&lt;P&gt;There are two versions of SharePoint that you can choose to install. It’s recommend that you install SharePoint Foundation (formerly known as WSS) if you only have 4 GB of RAM on your machine because there’s a lot less services running than the Server version (formerly known as MOSS). But if you need all the functionality of SharePoint Server then make sure you have enough of RAM. Just for fun I installed the Server version on my machine with only 4GB and it’s maxed out at 95% so I went with Foundation in the end. :-) &lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=906c9f5a-6505-4eba-bf24-95e423ac1703&amp;amp;displaylang=en" target=_blank mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyID=906c9f5a-6505-4eba-bf24-95e423ac1703&amp;amp;displaylang=en"&gt;Download Microsoft SharePoint Foundation 2010 Beta here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=77c30c6c-47fc-416d-88e7-8122534b3f37" target=_blank mce_href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=77c30c6c-47fc-416d-88e7-8122534b3f37"&gt;Download Microsoft SharePoint Server 2010 Beta here.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Note that you do not need to register or obtain a product key for installing SharePoint Foundation but you do for Server. The Product Key for Server is located at the bottom of the download page after you register (I missed it the first time so make sure you grab that before installing). &lt;/P&gt;
&lt;H4&gt;&lt;IMG style="DISPLAY: inline; MARGIN-LEFT: 0px; MARGIN-RIGHT: 0px" align=left src="http://i.msdn.microsoft.com/ee402630.Sharepoint_lg(en-us,MSDN.10).png" mce_src="http://i.msdn.microsoft.com/ee402630.Sharepoint_lg(en-us,MSDN.10).png"&gt; &lt;BR&gt;Installing SharePoint 2010 Beta on Windows 7&lt;/H4&gt;
&lt;P&gt;&lt;BR&gt;Read these instructions carefully: &lt;A href="http://msdn.microsoft.com/en-us/library/ee554869(office.14).aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ee554869(office.14).aspx"&gt;Setting Up the Development Environment for SharePoint Server&lt;/A&gt;&lt;STRONG&gt;&lt;/STRONG&gt;.&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;These are the instructions you’ll need to follow with a few additions I’ve added below as you go. Now that you’ve got your 64-bit Windows 7 VHD (are logged in as an administrator account) and downloaded SharePoint 2010 Beta you’re ready to proceed to Step 2 in the instructions. &lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Step 2: Install the Prerequisites for SharePoint 2010&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;There are a lot of prerequisites that you’ll need to install before you get to actually installing the SharePoint Beta. Follow all the instructions in Step 2 exactly as it says for Windows 7 to install all the prereqs and Windows features. But note that figure 3 in bullet #9 is incorrect. WCF Non-HTTP Activation should appear as checked. The script in bullet #8 is correct, it’s just a problem with the screenshot so don’t get confused. &lt;/P&gt;
&lt;P&gt;Next reboot. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;BEFORE &lt;/STRONG&gt;going to Step 3, you will need to install a WCF hotfix &lt;A href="http://blogs.msdn.com/sharepointdeveloperdocs/archive/2009/11/20/sharepoint-2010-beta-release-known-issues.aspx" target=_blank mce_href="http://blogs.msdn.com/sharepointdeveloperdocs/archive/2009/11/20/sharepoint-2010-beta-release-known-issues.aspx"&gt;as described in this post&lt;/A&gt; which fixes an "Unrecognized attribute 'allowInsecureTransport'" error. The WCF &lt;A href="http://go.microsoft.com/fwlink/?LinkID=166231" target=_blank mce_href="http://go.microsoft.com/fwlink/?LinkID=166231"&gt;hotfix for Windows 7 is available here&lt;/A&gt;. After installing this hotfix, reboot.&lt;/P&gt;
&lt;P&gt;Now you’re at Step 3 and ready to install SharePoint. &lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Step 3: Install SharePoint 2010&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Follow the instructions listed in this step to install SharePoint until you get to bullet #5. When you get here, you need to download and install the &lt;A href="http://support.microsoft.com/kb/970315" target=_blank mce_href="http://support.microsoft.com/kb/970315"&gt;SQL Server 2008 KB 970315 x64&lt;/A&gt; hotfix SQL_Server_2008_SP1_Cumulative_Update_2 build &lt;BR&gt;10.00.2714.00 which you get to by clicking the &lt;A href="http://support.microsoft.com/hotfix/KBHotfix.aspx?kbnum=970315&amp;amp;kbln=en-us" target=_blank mce_href="http://support.microsoft.com/hotfix/KBHotfix.aspx?kbnum=970315&amp;amp;kbln=en-us"&gt;View and request hotfix downloads&lt;/A&gt;&lt;EM&gt;&lt;/EM&gt; link at the top of the KB article. &lt;/P&gt;
&lt;P&gt;When installing this though I got the error "Invoke or BeginInvoke cannot be called on a control until the window handle has been created." To resolve it, I closed the all open windows including the SharePoint Configuration wizard (which is sitting open after SharePoint is installed) and then I reran the hotfix. Not sure what is going on here but it looks like it’s a &lt;A href="http://blogs.msdn.com/petersad/archive/2009/08/14/invoke-or-begininvoke-cannot-be-called-on-a-control-until-the-window-handle-has-been-created.aspx" target=_blank mce_href="http://blogs.msdn.com/petersad/archive/2009/08/14/invoke-or-begininvoke-cannot-be-called-on-a-control-until-the-window-handle-has-been-created.aspx"&gt;known issue on Win 7 64 according to this post&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;After that successfully installed I rebooted again. &lt;/P&gt;
&lt;P&gt;Now you need to run the SharePoint Configuration wizard, Start –&amp;gt; Programs –&amp;gt; Microsoft SharePoint 2010 Products –&amp;gt; SharePoint 2010 Products Configuration. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Note to domain users:&lt;/STRONG&gt; If you are installing as an administrator but your account is part of a domain, you will need to make sure you have online access to the domain controller! Otherwise configuration will fail on Step 2 with “Exception: Microsoft.SharePoint.SPException: User cannot be found.” This happens even though you select to install the standalone version. This bit me because I was installing on a laptop at home and was not on the corporate domain. I had to start my VPN and then I was good to go, until step 5 that is. ;-) &lt;/P&gt;
&lt;P&gt;On Step 5 I ran into another error “Failed to register SharePoint services. An exception of type System.ServiceProcess.TimeoutException was thrown.” This happened when I was installing the Server version and not Foundation. However &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010general/thread/d5bc40dc-88cf-42b5-8a6c-120e5a8e1dc4" target=_blank mce_href="http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010general/thread/d5bc40dc-88cf-42b5-8a6c-120e5a8e1dc4"&gt;I found a thread&lt;/A&gt; that told me this is related to low memory so I closed some other programs I had running and tried it again and it ran fine. This is why you should make sure you have enough memory before starting. ;-)&lt;/P&gt;
&lt;P&gt;You made it! SharePoint 2010 Beta should now be installed. To verify, open your browser to http://&lt;EM&gt;&amp;lt;MachineName&amp;gt; &lt;/EM&gt;and you should be able to start playing with your new SharePoint site. &lt;STRONG&gt;&lt;IMG style="MARGIN: 0px 10px 0px 0px; DISPLAY: inline" align=left src="http://i.msdn.microsoft.com/ee402630.VisualStudio_lg(en-us,MSDN.10).png" mce_src="http://i.msdn.microsoft.com/ee402630.VisualStudio_lg(en-us,MSDN.10).png"&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;H4&gt;Installing Visual Studio 2010 Beta 2&lt;/H4&gt;
&lt;P&gt;&lt;BR&gt;Everything should be super easy to install now but just in case you may want to save your VHD after you get SharePoint successfully installed ;-). &lt;/P&gt;
&lt;P&gt;You’ll need Visual Studio 2010 Beta Professional edition or higher to work with Office &amp;amp; SharePoint. I just picked the whole she-bang, Visual Studio 2010 Ultimate. I used the web installer but you can also choose the ISO package if you want to bring it all down once. &lt;/P&gt;
&lt;P&gt;&lt;A href="http://go.microsoft.com/fwlink/?LinkID=165573" target=_blank mce_href="http://go.microsoft.com/fwlink/?LinkID=165573"&gt;Download Visual Studio 2010 Ultimate (web bootstrapper)&lt;/A&gt; (See &lt;A href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx"&gt;this page for more&lt;/A&gt; download options).&lt;/P&gt;
&lt;P&gt;There was no hitch to install all the components of Visual Studio 2010 and .NET Framework 4. It took me about 35 minutes to wait for it to complete with one reboot in the middle. For more information, see the &lt;A href="http://go.microsoft.com/fwlink/?LinkID=166199" target=_blank mce_href="http://go.microsoft.com/fwlink/?LinkID=166199"&gt;Visual Studio 2010 Beta 2 Readme&lt;/A&gt;, &lt;A href="http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx" target=_blank mce_href="http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx"&gt;Visual Studio 2010 Product Information&lt;/A&gt; and &lt;A href="http://msdn.microsoft.com/en-us/vstudio/dd441784.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/vstudio/dd441784.aspx"&gt;Featured Overviews and Walkthroughs&lt;/A&gt;.&lt;/P&gt;
&lt;H4&gt;&lt;STRONG&gt;&lt;IMG style="MARGIN: 0px; DISPLAY: inline" align=left src="http://i.msdn.microsoft.com/ee402630.Office2010_lg(en-us,MSDN.10).png" mce_src="http://i.msdn.microsoft.com/ee402630.Office2010_lg(en-us,MSDN.10).png"&gt;&amp;nbsp; &lt;BR&gt;&lt;/STRONG&gt;Installing Microsoft Office 2010 Beta&lt;/H4&gt;
&lt;P&gt;&lt;BR&gt;This one is probably the easiest to install. &lt;/P&gt;
&lt;P&gt;&lt;A title=http://msdn.microsoft.com/en-us/evalcenter/ee390822.aspx href="http://msdn.microsoft.com/en-us/evalcenter/ee390822.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/evalcenter/ee390822.aspx"&gt;Download Office 2010 Beta here.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Scroll to the bottom of the page to get started. You’ll need to register and then you’ll get a product key page with a download button at the bottom. Save your product key and then select the language to download. Note that it says “&lt;EM&gt;Download the 32-bit (x86) version:&lt;/EM&gt;” but the download will include both 32-bit and 64-bit so don’t worry. &lt;/P&gt;
&lt;P&gt;Once you click the download button you’ll actually have to install a little download manager to get the setup package. Once you download the package, click on the ProfessionalPlus.exe to start the install. You’ll see a big button “Install Now”. Click that and in about 15 minutes you’ll have Office installed. It doesn’t get much easier than that.&lt;/P&gt;
&lt;H4&gt;&lt;STRONG&gt;Let ‘er Rip!&lt;A href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/SettingupWindows7forOfficeSharePoint2010_CA0B/spsite_4.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/SettingupWindows7forOfficeSharePoint2010_CA0B/spsite_4.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; MARGIN: 0px 0px 0px 10px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=spsite border=0 alt=spsite align=right src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/SettingupWindows7forOfficeSharePoint2010_CA0B/spsite_thumb_1.png" width=341 height=362 mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/SettingupWindows7forOfficeSharePoint2010_CA0B/spsite_thumb_1.png"&gt;&lt;/A&gt;&lt;/STRONG&gt;&lt;/H4&gt;
&lt;P&gt;Okay so you want to be able to test these things are all installed and playing happily. In order to develop against SharePoint you’ll need to open Visual Studio as &lt;STRONG&gt;run as Administrator. &lt;/STRONG&gt;Next, open the Server Explorer and you should see a SharePoint Connections node. Expand that node and you should be able to browse your SharePoint site.&lt;/P&gt;
&lt;P&gt;You should also explore some of the awesome new project templates under the Office &amp;gt; 2010 and SharePoint &amp;gt; 2010 nodes in the File &amp;gt; New Project dialog. &lt;/P&gt;
&lt;H4&gt;What’s Next?&lt;/H4&gt;
&lt;P&gt;Now it’s time for us to learn how to use these Office and SharePoint tools in Visual Studio! Check out some of my favorite resources:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Office 2010 Development Resources&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&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;Office Development in Visual Studio 2010 Beta Samples, Walkthroughs and Videos&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://social.msdn.microsoft.com/Forums/en-US/officedevelopmentprerelease/threads" target=_blank mce_href="http://social.msdn.microsoft.com/Forums/en-US/officedevelopmentprerelease/threads"&gt;Office Development in Visual Studio 2010 Forums&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/vsto/default.aspx" target=_blank mce_href="http://blogs.msdn.com/vsto/default.aspx"&gt;Office Development with Visual Studio Team Blog&lt;/A&gt;&amp;nbsp; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/office/ee513173.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/office/ee513173.aspx"&gt;Office 2010 Beta Resources&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.technet.com/gray_knowlton/archive/2009/11/10/office-2010-application-compatibility-deep-dive-on-the-code-compatibility-inspector.aspx" target=_blank mce_href="http://blogs.technet.com/gray_knowlton/archive/2009/11/10/office-2010-application-compatibility-deep-dive-on-the-code-compatibility-inspector.aspx"&gt;Office 2010 Application Compatibility Tools&lt;/A&gt; &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;SharePoint 2010 Development Resources&lt;/STRONG&gt;&lt;/P&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/vstudio/dd441784.aspx#Sharepoint" target=_blank mce_href="http://msdn.microsoft.com/en-us/vstudio/dd441784.aspx#Sharepoint"&gt;SharePoint Development in Visual Studio 2010 Walkthroughs&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://channel9.msdn.com/tags/Sharepoint+2010+Beta/" target=_blank mce_href="http://channel9.msdn.com/tags/Sharepoint+2010+Beta/"&gt;SharePoint Development in Visual Studio 2010 Videos&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopmentprerelease/threads" target=_blank mce_href="http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopmentprerelease/threads"&gt;SharePoint Development Forums&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/sharepoint/ee513147.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/sharepoint/ee513147.aspx"&gt;SharePoint 2010 Development Resources&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/sharepoint/" target=_blank mce_href="http://blogs.msdn.com/sharepoint/"&gt;SharePoint Team Blog&lt;/A&gt; 
&lt;P&gt;Enjoy!&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9931766" width="1" height="1"&gt;</description><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/SharePoint/default.aspx">SharePoint</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/Windows+7/default.aspx">Windows 7</category></item><item><title>New Learning Resources on the VSTO Developer Center</title><link>http://blogs.msdn.com/bethmassi/archive/2009/12/01/new-learning-resources-on-the-vsto-developer-center.aspx</link><pubDate>Wed, 02 Dec 2009 01:43:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9931202</guid><dc:creator>Beth Massi</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9931202.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9931202</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9931202</wfw:comment><description>&lt;p&gt;Last week we revamped the &lt;a href="http://msdn.microsoft.com/en-us/vsto/dd162433.aspx" target="_blank"&gt;Learn pages on the VSTO Developer Center&lt;/a&gt; with more content that allows you to pivot on more fine-grained topics and tasks under each type of Office solution. We’ve changed the layout of these pages so that you can browse for a type of solution (right now we have &lt;a href="http://msdn.microsoft.com/en-us/vsto/dd162436.aspx" target="_blank"&gt;Excel&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/vsto/dd164295.aspx" target="_blank"&gt;Word&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/vsto/dd162450.aspx" target="_blank"&gt;Outlook&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/vsto/dd162450.aspx" target="_blank"&gt;Deployment&lt;/a&gt;) and then you can drill down into the specific topics to reveal articles and videos underneath. As you select a topic on the left, the content changes on the right so &lt;a href="http://msdn.microsoft.com/en-us/vsto/dd162436.aspx" target="_blank"&gt;check it out&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/NewLearningResourcesontheVSTODeveloperCe_F7BF/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/NewLearningResourcesontheVSTODeveloperCe_F7BF/image_thumb_1.png" width="674" height="430" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;We’ve gone through and picked key content in the &lt;a href="http://msdn.microsoft.com/en-us/library/d2tx7z6d.aspx" target="_blank"&gt;Visual Studio&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/bb726434.aspx" target="_blank"&gt;Office&lt;/a&gt; MSDN libraries, other Developer Centers and blogs to bring you a better integrated learning experience -- especially if you’re just getting started programming Office solutions with Visual Studio. Let me know what topics I’ve missed by making a comment to the end of this post or by &lt;a href="http://blogs.msdn.com/bethmassi/contact.aspx" target="_blank"&gt;contacting me directly&lt;/a&gt; and I’ll get them added. Also let me know how you like this layout, I’m planning on taking this approach to the &lt;a href="http://msdn.microsoft.com/en-us/vbasic/default.aspx" target="_blank"&gt;Visual Basic&lt;/a&gt; Developer Center as well. &lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9931202" width="1" height="1"&gt;</description><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/Office/default.aspx">Office</category><category domain="http://blogs.msdn.com/bethmassi/archive/tags/VSTO/default.aspx">VSTO</category></item><item><title>SF Bay.NET UG Tonight: Create a Custom Outlook Add-In using VSTO</title><link>http://blogs.msdn.com/bethmassi/archive/2009/11/18/sf-bay-net-ug-tonight-create-a-custom-outlook-add-in-using-vsto.aspx</link><pubDate>Wed, 18 Nov 2009 22:23:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9924788</guid><dc:creator>Beth Massi</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9924788.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9924788</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9924788</wfw:comment><description>&lt;p&gt;If you’re in the Bay Area, come on out to downtown SF where &lt;a href="http://robindotnet.wordpress.com/" target="_blank"&gt;Robin&lt;/a&gt; will be talking about Outlook Add-ins tonight. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.baynetug.org/DesktopModules/DetailXEvents.aspx?ItemID=393&amp;amp;mid=49" target="_blank"&gt;&lt;strong&gt;Create a custom Outlook Add-In using VSTO&lt;/strong&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;When&lt;/strong&gt;:&amp;#160; Wednesday, 11/18/2009 at 6:30 PM    &lt;br /&gt;&lt;strong&gt;Where&lt;/strong&gt;: Microsoft San Francisco Office, 835 Market Street, Suite 700, San Francisco&lt;/p&gt;  &lt;p&gt;Visual Studio 2008 and Office 2007 made it easier than ever to create add-ins for Office. In this session, Robin Shahan will show how to program an add-in for Outlook that modifies the Quick Access Toolbar, adds your own section to the Office Ribbon, and adds a command bar to the main Outlook window. Then she will show you how to deploy the application via ClickOnce deployment.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Presenter's Bio&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Robin Shahan has over 20 years of experience developing complex, business-critical applications. She is currently the Director of Engineering for GoldMail, a small company based in San Francisco whose product provides voice-over-visual messages. Robin is a moderator in the MSDN Forum for ClickOnce and Setup &amp;amp; Deployment projects, and vows to learn Windows Installer some day. She is also a Microsoft MVP in Client App Dev; you can follow her blog at &lt;a href="http://robindotnet.wordpress.com/" target="_blank"&gt;http://robindotnet.wordpress.com/&lt;/a&gt;, or on Twitter, @RobinDotNet.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.baynetug.org/DesktopModules/DetailXEvents.aspx?ItemID=393&amp;amp;mid=49" target="_blank"&gt;&lt;strong&gt;Register for this talk tonight on the Bay.NET website&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;See you there!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9924788" 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/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></item><item><title>Interop Between VBA and Visual Studio Office Solutions (VSTO)</title><link>http://blogs.msdn.com/bethmassi/archive/2009/11/05/interop-between-vba-and-visual-studio-office-solutions-vsto.aspx</link><pubDate>Fri, 06 Nov 2009 05:03:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9918383</guid><dc:creator>Beth Massi</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9918383.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9918383</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9918383</wfw:comment><description>&lt;p&gt;Couple weeks ago when &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/10/20/sdc-2009-recap-surprise.aspx" target="_blank"&gt;I was in Holland speaking at SDC&lt;/a&gt; an attendee asked me how he could call methods in an Office solution (VSTO) from VBA functions defined in a document and vice versa. I thought I’d follow up with a post on how to do this, but first a little background on why this architecture would make sense. &lt;/p&gt;  &lt;p&gt;There are many reasons why you would build an Office solution using Visual Studio (VSTO) as opposed to a pure VBA solution. &lt;a href="http://geeks.netindonesia.net/blogs/andriyadi/default.aspx"&gt;Andri Yadi&lt;/a&gt;, VSTO MVP, &lt;a href="http://geeks.netindonesia.net/blogs/andriyadi/archive/2008/08/20/vba-vs-vsto.aspx" target="_blank"&gt;wrote a great piece on his blog a while back explaining the benefits of VSTO compared to VBA&lt;/a&gt;. He broke it down into 10 areas, of which the main benefits are the tools and designers you have available in Visual Studio as well as the entire .NET framework and modern languages at your disposal. &lt;/p&gt;  &lt;p&gt;However, there are probably many VBA assets that people in your company have already written, like complex algorithms or other business logic that you really don’t want to rewrite. Or maybe you still want to allow users to customize these functions in the VBA editor but it’s necessary for you to call them from your .NET code. &lt;/p&gt;  &lt;p&gt;Likewise, you may want to develop a customization that takes advantage of WCF services or a WPF UI, modern language features, or any other feature of the .NET framework that would be difficult or impossible to do in VBA, and you want the user to be able to access these methods from their VBA functions. The attendee at SDC didn’t go into much detail on what his Office customization was doing exactly but he wanted to make some of his public methods available to his VBA users and this makes sense in a lot of situations. Luckily Visual Studio makes this very easy to do. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Creating an Excel Document Customization&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;For this example I’ll create an Excel document customization that accesses data through a WCF service and does some calculations on that data. The calculations, however, will be in VBA. To access the remote data over the internet I’ll create an ADO.NET Data Service. I want to pull up data in a Northwind view called &lt;em&gt;Sales Totals By Amount&lt;/em&gt;. I’ve shown how to create an ADO.NET Data Service many times before so I won’t go into too much detail here. Please refer to the steps shown in the &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/01/09/using-ado-net-data-services.aspx" target="_blank"&gt;Using ADO.NET Data Services&lt;/a&gt; article. The only difference in this case is I selected the View &lt;em&gt;Sales Totals By Amount&lt;/em&gt; into my Entity Framework model when I performed that step. &lt;/p&gt;  &lt;p&gt;I have an Excel macro-enabled workbook that already has a simple VBA function that Sums all the columns below the first row. The function is sitting in a module called MyFunctions. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/InteroptoVBAFunctionsFromYourVisualStudi_A978/image_2.png" target="_blank"&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/InteroptoVBAFunctionsFromYourVisualStudi_A978/image_thumb.png" width="669" height="251" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;To create the new&amp;#160; Excel workbook customization I’m going to add a new project to my solution and select Office 2007 Excel Workbook. Next it will ask if you want to create a new document or use an existing one, here’s where I’ll specify the macro-enabled workbook I already have above.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/InteroptoVBAFunctionsFromYourVisualStudi_A978/image_6.png" target="_blank"&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/InteroptoVBAFunctionsFromYourVisualStudi_A978/image_thumb_2.png" width="613" height="446" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Next Add a Service Reference to the ADO.NET Data Service (which I called NorthwindReportService) &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/01/09/using-ado-net-data-services.aspx" target="_blank"&gt;just like I showed here&lt;/a&gt; and copy the URI into your clipboard. Then create a setting to store the URI, just double-click on My Project (Properties in C#) and select the Settings tab and enter an application scope property called ServiceURI.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/InteroptoVBAFunctionsFromYourVisualStudi_A978/image_8.png" target="_blank"&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/InteroptoVBAFunctionsFromYourVisualStudi_A978/image_thumb_3.png" width="684" height="115" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;When you add the service reference this generates client-side proxy types that you can use. I’m going to bind the data returned from Sales_Totals_by_Amount to an Excel ListObject. Open the Data Source window (Data –&amp;gt; Show Data Sources) and then add a new data source (Data –&amp;gt; Add New Data Source…). In the Data Source Connection Wizard select Object, then Next, then expand the types in your project’s NorthwindReportService namespace. Select Sales_Totals_by_Amount and then click Finish and you will see the type’s properties appear in the Data Sources Window:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/InteroptoVBAFunctionsFromYourVisualStudi_A978/image_10.png" target="_blank"&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/InteroptoVBAFunctionsFromYourVisualStudi_A978/image_thumb_4.png" width="670" height="515" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Double-click on Sheet1 in the project and drag the Sales_Totals_by_Amount from the Data Sources window onto the &lt;strong&gt;second &lt;/strong&gt;row of the sheet (our macro is going to sum into the first row so we want to place the data starting on the second row). This will automatically set up a BindingSource in the system tray that we will use to set our list of data coming from the service. If you are familiar with Winforms development this should seem very familiar. The ListObject is the main data object you work with in Excel solutions. For this example I’m going to select the OrderId column, right-click and then Delete. I’ll do the same to the ShippedDate column because I only want to display the CompanyName and SaleAmount for this example. Finally I’ll set the formatting (Home Tab on the Excel Designer) to Currency for the first cell. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/InteroptoVBAFunctionsFromYourVisualStudi_A978/image_12.png" target="_blank"&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/InteroptoVBAFunctionsFromYourVisualStudi_A978/image_thumb_5.png" width="589" height="373" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now we’re ready to write some code to load our data. Right-click on ThisWorkbook and select View Code. Here I’m going to create a Friend ReadOnly Property so we can easily access the service reference from anywhere in the project. I’m making this Friend so that it won’t be visible outside of the .NET assembly. I’m also creating a Public method that gets the data from our service and optionally accepts a Company Name. The results are then set to the DataSource of the ListObject’s BindingSource on Sheet1:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;VBATest.NorthwindReportService

&lt;span style="color: blue"&gt;Public Class &lt;/span&gt;ThisWorkbook

    &lt;span style="color: blue"&gt;Private &lt;/span&gt;_ReportService &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;Friend ReadOnly Property &lt;/span&gt;ReportService() &lt;span style="color: blue"&gt;As &lt;/span&gt;NorthwindEntities
        &lt;span style="color: blue"&gt;Get
            Return &lt;/span&gt;_ReportService
        &lt;span style="color: blue"&gt;End Get
    End Property

    Public Sub &lt;/span&gt;GetData(&lt;span style="color: blue"&gt;Optional ByVal &lt;/span&gt;companyName = &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;)
        &lt;span style="color: blue"&gt;Try
            If &lt;/span&gt;Globals.Sheet1 &lt;span style="color: blue"&gt;IsNot Nothing Then

                Dim &lt;/span&gt;results &lt;span style="color: blue"&gt;As &lt;/span&gt;IEnumerable(&lt;span style="color: blue"&gt;Of &lt;/span&gt;Sales_Totals_by_Amount)

                &lt;span style="color: blue"&gt;If &lt;/span&gt;companyName = &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;Then
                    &lt;/span&gt;results = &lt;span style="color: blue"&gt;Me&lt;/span&gt;.ReportService.Sales_Totals_by_Amount
                &lt;span style="color: blue"&gt;Else
                    &lt;/span&gt;results = &lt;span style="color: blue"&gt;From &lt;/span&gt;s &lt;span style="color: blue"&gt;In Me&lt;/span&gt;.ReportService.Sales_Totals_by_Amount _
                              &lt;span style="color: blue"&gt;Where &lt;/span&gt;s.CompanyName.StartsWith(companyName)
                &lt;span style="color: blue"&gt;End If

                &lt;/span&gt;Globals.Sheet1.Sales_Totals_by_AmountBindingSource.DataSource = results.ToList()
            &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;'TODO: Error Handling
            &lt;/span&gt;MsgBox(ex.ToString())
        &lt;span style="color: blue"&gt;End Try
    End Sub

    Private Sub &lt;/span&gt;ThisWorkbook_Startup() &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;ThisWorkbook_Shutdown() &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;&lt;strong&gt;Calling VBA from VSTO&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next I want to create a button on the ribbon that will first call the GetData method, then select the first cell in Sheet1, and finally call the VBA function SumBelow. In order to call a VBA method from VSTO you call Globals.ThisWorkbook.Application.Run passing it the&lt;strong&gt; full name&lt;/strong&gt; to the VBA method. For this example that would be VBATest.xlsm!MyFunctions.SumBelow. &lt;/p&gt;

&lt;p&gt;Add a New Item to the project and select Office, Ribbon (Visual Designer) and then drag a Button from the Office Ribbon Controls to the Group and Label it “Get Data”. I also specified an OfficeImageId to make it look pretty. (BTW, a nice way to browse the Office Images is to &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=46B6BF86-E35D-4870-B214-4D7B72B02BF9&amp;amp;displaylang=en" target="_blank"&gt;install the VSTO Power Tools&lt;/a&gt; and install the RibbonID Add-in like &lt;a href="http://msdn.microsoft.com/en-us/vsto/dd229920.aspx" target="_blank"&gt;Ty shows in this video&lt;/a&gt;.)&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/InteroptoVBAFunctionsFromYourVisualStudi_A978/image_14.png" target="_blank"&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/InteroptoVBAFunctionsFromYourVisualStudi_A978/image_thumb_6.png" width="675" height="400" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Double-click on the Get Data button to add a click event handler and we’ll write the following code to load all the data and then call the VBA function. You need to make sure you set up proper error handling here because if the VBA function is removed or renamed the code here will fail. This code will also fail if the appropriate access is not granted to VBA macros in Excel. By default, VBA macros are not enabled but you can enable them on a per workbook basis (there’s a button at the top of the first sheet when you run it). This scenario assumes you have existing VBA code that has permission to run and you’re now calling those existing functions from VSTO.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;VBATest.NorthwindReportService
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;Microsoft.Office.Tools.Ribbon

&lt;span style="color: blue"&gt;Public Class &lt;/span&gt;Ribbon1

    &lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;Button1_Click() &lt;span style="color: blue"&gt;Handles &lt;/span&gt;Button1.Click
        &lt;span style="color: green"&gt;'load the data from the service
        &lt;/span&gt;Globals.ThisWorkbook.GetData()
        &lt;span style="color: blue"&gt;Try
            &lt;/span&gt;&lt;span style="color: green"&gt;'Make sure the first cell is selected
            &lt;/span&gt;Globals.Sheet1.Range(&lt;span style="color: #a31515"&gt;&amp;quot;A1&amp;quot;&lt;/span&gt;).Select()
            &lt;span style="color: green"&gt;'Run the VBA function. This will result in a runtime error if the function 
            ' is removed or renamed or not allowed to run so make sure to provide &lt;br /&gt;            ' adequate error handling.             
            &lt;/span&gt;Globals.ThisWorkbook.Application.Run(&lt;span style="color: #a31515"&gt;&amp;quot;VBATest.xlsm!MyFunctions.SumBelow&amp;quot;&lt;/span&gt;)
        &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: green"&gt;'Todo: Error handling
            &lt;/span&gt;MsgBox(ex.ToString())
        &lt;span style="color: blue"&gt;End Try
    End Sub
End Class&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Hit F5 to run. If you see a Security Warning (the default) that Macros are disabled, then just click Options and select “Enable this content”. Select the Add-Ins tab on the Ribbon and click the GetData button to see the data get loaded from the service and then the SumBelow VBA function will be called which will auto-sum the SaleAmount field and show the total in the first row.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Calling VSTO methods from VBA&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As you can see it’s really easy to call VBA code from your Office solution in Visual Studio (VSTO) but it’s also fragile because of the late-bound architecture and the requirement that macros be enabled for the Workbook. Like all late-bound code, you need to have adequate error handling to prevent crashes. Much less fragile is calling VSTO methods from VBA functions because these methods are compiled into your .NET assembly and exposed via COM-interop which makes them available to VBA. &lt;/p&gt;

&lt;p&gt;If we go back to our project and double-click on ThisWorkbook and look in the Properties window, you should see a property called EnableVbaCallers. Setting that Property to True will expose all Public methods in the ThisWorkbook class via COM to VBA. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/InteroptoVBAFunctionsFromYourVisualStudi_A978/image_16.png" target="_blank"&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/InteroptoVBAFunctionsFromYourVisualStudi_A978/image_thumb_7.png" width="325" height="196" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;If you now go back into the code-behind for ThisWorkbook you will see some COM attributes added to the class:&lt;/p&gt;

&lt;pre class="code"&gt;&amp;lt;Microsoft.VisualBasic.ComClassAttribute()&amp;gt; _
&amp;lt;System.Runtime.InteropServices.ComVisibleAttribute(&lt;span style="color: blue"&gt;True&lt;/span&gt;)&amp;gt; _
&lt;span style="color: blue"&gt;Public Class &lt;/span&gt;ThisWorkbook&lt;br /&gt;...&lt;/pre&gt;

&lt;p&gt;Now we can call the GetData method from VBA code. Hit F5 to run and enable the macros (if asked) on the Workbook again. Select the Developer tab and launch the Visual Basic editor. (If you don’t see a developer tab click the Office icon – the globe in the left-hand corner – select Excel Options, and then on the Popular tab check the “Show Developer tab in the Ribbon”.) &lt;/p&gt;

&lt;p&gt;Double-click on the ThisWorkbook and you will see that Visual Studio added a property to our VBA code for us called CallVSTOAssembly. This allows us to call any public method we defined in the ThisWorkbook class back in Visual Studio. Let’s add another function to the MyFunctions module that collects input from the user on the company name to look up and then fetches the data by calling the GetData method in .NET.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/InteroptoVBAFunctionsFromYourVisualStudi_A978/image_20.png" target="_blank"&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/InteroptoVBAFunctionsFromYourVisualStudi_A978/image_thumb_9.png" width="686" height="392" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Save your code here and close the VBA Editor. Now back on the Developer tab on the Ribbon select Macros and then you should see the one we just wrote called GetDataAndSumBelow, select it and click Run. It will prompt for a company name (just type ‘S’ for instance) and it will run the ADO.NET Data Service query via the call to the .NET GetData method and then will return and call the SumBelow VBA function. Cool! &lt;/p&gt;

&lt;p&gt;BUT WAIT… DON’T CLOSE EXCEL YET! &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tips Editing VBA Code when Debugging&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Because we wrote the second VBA function above while we were in debug mode in Visual Studio once we close Excel we will lose all the VBA code we wrote when we debug again. &lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/InteroptoVBAFunctionsFromYourVisualStudi_A978/image_22.png" target="_blank"&gt;&lt;img style="border-right-width: 0px; margin: 5px 10px 0px 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/InteroptoVBAFunctionsFromYourVisualStudi_A978/image_thumb_10.png" width="284" height="360" /&gt;&lt;/a&gt;Because of the way Visual Studio works with Office solutions, we aren’t actually editing the xlsm file in the project, we’re editing the running xlsm file in the \bin directory that has the VSTO solution attached. You &lt;strong&gt;cannot &lt;/strong&gt;just copy this one in the \bin folder back into the project otherwise Visual Studio will report an error that a customization is already attached to the document when you compile again. So what do we do?&lt;/p&gt;

&lt;p&gt;There’s probably other ways to do this but what I found the easiest was to open the Visual Basic editor again, select the MyFunctions module where all my code is stored and then right-click and select “Export File”. This will allow you to save the code outside the Workbook. Then when you debug again you can just import it by right-clicking again (delete the current one first). &lt;/p&gt;

&lt;p&gt;When you’re finally satisfied with your VBA – VSTO code interop, close Visual Studio and open the .xlsm file in the &lt;strong&gt;project directory&lt;/strong&gt; (not the \bin) and re-import your code again into that version. Then restart Visual Studio and it will be in there when you start debugging again. I find this easier than copying my code into the clipboard, closing VS, modifying the document, reopening VS every time. Just be aware of what version of the document you’re modifying when you tweak your VBA code and you should be OK.&lt;/p&gt;

&lt;p&gt;I’ve uploaded the code for this example onto Code Gallery so have a look: &lt;a title="http://code.msdn.microsoft.com/VBAVSTOInterop" href="http://code.msdn.microsoft.com/VBAVSTOInterop"&gt;http://code.msdn.microsoft.com/VBAVSTOInterop&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;More Resources&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For more information on VBA – VSTO interop with Visual Studio please check out the following resources:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163373.aspx" target="_blank"&gt;MSDN Magazine: Extend Your VBA Code With VSTO&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb931201.aspx" target="_blank"&gt;MSDN Article: VBA Interoperability with Visual Studio Tools for the Office System (3.0)&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb814696.aspx" target="_blank"&gt;Visual How To: Interoperability Between VBA and Visual Studio Tools for the Office System (3.0)&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/vsto/cc178910.aspx" target="_blank"&gt;How Do I: Call VSTO Code from VBA?&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/vsto/cc748594.aspx"&gt;How Do I: Enable an Office Application Add-In using a VSTO Add-in?&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=9918383" 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/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/VBA/default.aspx">VBA</category></item><item><title>Merging Text &amp; Photos into a Word Document using Open XML SDK</title><link>http://blogs.msdn.com/bethmassi/archive/2009/09/24/merging-text-photos-into-a-word-document-using-open-xml-sdk.aspx</link><pubDate>Fri, 25 Sep 2009 00:55:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9899172</guid><dc:creator>Beth Massi</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9899172.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9899172</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9899172</wfw:comment><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/09/23/mail-merging-into-a-single-word-document-using-xml-literals.aspx" target="_blank"&gt;Yesterday I posted&lt;/a&gt; about how we could create a letter generator (mail merge) that took data from a database to create a Word 2007 document using the System.IO.Packaging class. I showed how to take data from Northwind using a single LINQ query to create XDocument objects representing letters to customers and then create a single document of all the data using XML Literals. &lt;/p&gt; &lt;p&gt;Today I want to show how we can embed images into the documents as well as text. Since we’re using Northwind for this example, we’ll use the Employee.Photo field from that database. &lt;/p&gt; &lt;p&gt;&lt;strong&gt;The Letter Template with Photo&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;The first thing to do is create a letter template with our field placeholders as well as an image placeholder. We’ll also need to insert a page break at the end because we’re going to merge all the letters into a single document for easy printing:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MergingTextPhotosintoaSingleWordDocument_E6F4/image_2.png" target="_blank"&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/MergingTextPhotosintoaSingleWordDocument_E6F4/image_thumb.png" width="668" height="555"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;The next step is to grab the document.xml from this docx file. Because it’s an Open XML package, as I showed in &lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/09/23/mail-merging-into-a-single-word-document-using-xml-literals.aspx" target="_blank"&gt;yesterday’s post&lt;/a&gt;, we can just rename this file with a .zip extension temporarily and drill into the word\document.xml. However, there’s an easier way to work with these packages by installing the &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;Open XML package editor&lt;/a&gt; Visual Studio add-in from 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 download&lt;/a&gt;. &lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MergingTextPhotosintoaSingleWordDocument_E6F4/image_8.png" target="_blank"&gt;&lt;img style="border-right-width: 0px; margin: 0px 10px 0px 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/MergingTextPhotosintoaSingleWordDocument_E6F4/image_thumb_3.png" width="457" height="327"&gt;&lt;/a&gt;Once you install 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;, save this template in your project. Then you can just double-click on the .docx file in the Solution Explorer and it will open the package editor (it also works with .pptx and .xslx files). Now you can drill into the document.xml directly in Visual Studio and inspect all the parts of the package easily. &lt;/p&gt; &lt;p&gt;The difference between this template and the template we used yesterday is there is an image imbedded into the document. So you will see an image embedded into the package in the media folder. This is referred to as an “image part”. This part is linked to the “main document part” which is the word\document.xml file. The Open XML package editor shows the links (relationships) to all the parts. When you look at the relationship properties you’ll see that it has a unique ID. This is the same ID that you will see in the main document part at the point where we embedded the image, in our case it’s set to &lt;strong&gt;rId4&lt;/strong&gt;. (I’ve omitted all the WordProccessingML 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;xml &lt;/span&gt;&lt;span style="color: red"&gt;version&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;1.0&lt;/span&gt;" &lt;span style="color: red"&gt;encoding&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;utf-8&lt;/span&gt;" &lt;span style="color: red"&gt;standalone&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;yes&lt;/span&gt;"&lt;span style="color: blue"&gt;?&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;w:document ...&lt;br&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;w:body&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt; ...&lt;/span&gt;&lt;/pre&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;w:drawing&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt; ...&lt;br&gt;&lt;/pre&gt;&lt;/span&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;              &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;a:graphic &lt;/span&gt;&lt;span style="color: red"&gt;xmlns:a&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;http://schemas.openxmlformats.org/drawingml/2006/main&lt;/span&gt;"&lt;span style="color: blue"&gt;&amp;gt;
              &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;a:graphicData &lt;/span&gt;&lt;span style="color: red"&gt;uri&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;http://schemas.openxmlformats.org/drawingml/2006/picture&lt;/span&gt;"&lt;span style="color: blue"&gt;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;pic:pic &lt;/span&gt;&lt;span style="color: red"&gt;xmlns:pic&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;http://schemas.openxmlformats.org/drawingml/2006/picture&lt;/span&gt;"&lt;span style="color: blue"&gt;&amp;gt;
                  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;pic:nvPicPr&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;pic:cNvPr &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&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;=&lt;/span&gt;"&lt;span style="color: blue"&gt;image1.png&lt;/span&gt;"&lt;span style="color: blue"&gt;/&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;pic:cNvPicPr&lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;
                  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;pic:nvPicPr&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;pic:blipFill&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;a:blip &lt;/span&gt;&lt;strong&gt;&lt;span style="color: red"&gt;r:embed&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;rId4&lt;/span&gt;"&lt;/strong&gt; &lt;span style="color: red"&gt;cstate&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;print&lt;/span&gt;"&lt;span style="color: blue"&gt;/&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;a:stretch&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;a:fillRect&lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;
                    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;a:stretch&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;pic:blipFill&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;pic:spPr&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;a:xfrm&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;a:off &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: blue"&gt;0&lt;/span&gt;" &lt;span style="color: red"&gt;y&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;0&lt;/span&gt;"&lt;span style="color: blue"&gt;/&amp;gt;
                      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;a:ext &lt;/span&gt;&lt;span style="color: red"&gt;cx&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;1829055&lt;/span&gt;" &lt;span style="color: red"&gt;cy&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;2124372&lt;/span&gt;"&lt;span style="color: blue"&gt;/&amp;gt;
                    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;a:xfrm&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;a:prstGeom &lt;/span&gt;&lt;span style="color: red"&gt;prst&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;rect&lt;/span&gt;"&lt;span style="color: blue"&gt;&amp;gt;
                      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;a:avLst&lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;
                    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;a:prstGeom&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;pic:spPr&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;pic:pic&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
              &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;a:graphicData&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;a:graphic&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt; ...
          &lt;/span&gt;&lt;span style="color: blue"&gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;w:drawing&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt; ...&lt;br&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;w:p &lt;/span&gt;&lt;span style="color: red"&gt;w:rsidR&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;00622A50&lt;/span&gt;" &lt;span style="color: red"&gt;w:rsidRDefault&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;00622A50&lt;/span&gt;"&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;w:r&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;w:br &lt;/span&gt;&lt;span style="color: red"&gt;w:type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;page&lt;/span&gt;"&lt;span style="color: blue"&gt;/&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;w:r&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;w:p&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt; ...&lt;/span&gt;&lt;/pre&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;w:body&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;w:document&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;&lt;strong&gt;Installing the Open XML SDK&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;As I mentioned yesterday, manipulating the package directly with the System.IO.Packaging classes gets a little bit tricky when you have to start adding embedded images and objects and linking them together. Instead, it’s easier to use the Open XML SDK to do this because it will handle linking new image parts we add to the package automatically for us. The SDK provides a strongly-typed way of accessing the parts in a package so it cuts down on the amount of code you have to write yourself.&amp;nbsp; Version 1.0 requires only .NET 2.0, Version 2 requires .NET 3.5 and uses LINQ to provide more functionality when querying the parts. This version is currently a CTP. For what we’re doing you can use either version but I have Version 2 installed. &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=AD0B72FB-4A1D-4C52-BDB5-7DD7E816D046&amp;amp;displaylang=en" target="_blank"&gt;Download Open XML Format SDK 1.0&lt;/a&gt; 
&lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c6e744e5-36e9-45f5-8d8c-331df206e0d0&amp;amp;DisplayLang=en" target="_blank"&gt;Download Open XML Format SDK 2.0&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;The assembly that is installed in the GAC when you install the SDK is called DocumentFormat.OpenXml.dll and you’ll need to add a project reference to this. When you distribute your application you can simply xcopy the assembly with your application for easy deployment. (After you add the reference, select it in the Server Explorer and then in the Properties window set Copy Local to True in order to have it outputted to the \bin folder when you build your application.)&lt;/p&gt;
&lt;p&gt;Now we can add the namespace imports we’ll be working with at the top of our program, including the DocumentFormat.OpenXml.Packaging namespace:&lt;/p&gt;&lt;pre class="code"&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:w&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;http://schemas.openxmlformats.org/wordprocessingml/2006/main&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Xml
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.IO
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;DocumentFormat.OpenXml.Packaging&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;&lt;strong&gt;Modifying the Letter Class and LINQ Query to Get the Photo&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In order to create letters for our customers in the database, we want to end up with a collection of XDocuments with our data merged into them. I created a Letter class that has two properties, CustomerID As String and Document As XDocument. We’re also going to add a new property for the photo byte array called EmployeePhoto As Byte() and OrderID as Integer. Next we need to modify the query so that it selects the photo as well as add the above WordProcessingML into our XML Literal to specify where the image should appear in the document. Because the relationship IDs must be unique, I’m going to use the OrderID as the suffix for the relationship ID for each of the images we want to embed. Like before, we can use embedded expressions to merge the data into the right places in the XDocument. 
&lt;p&gt;(I’ve omitted all the XML with the embedded expressions for clarity, take a loot at &lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=openxmlvb&amp;amp;DownloadId=7325"&gt;the code sample&lt;/a&gt; for the whole listing.) The bolded areas show the modified sections of the query:&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;letters = _
&lt;span style="color: blue"&gt;  From &lt;/span&gt;Order &lt;span style="color: blue"&gt;In &lt;/span&gt;db.Orders _
&lt;span style="color: blue"&gt;  Join &lt;/span&gt;Employee &lt;span style="color: blue"&gt;In &lt;/span&gt;db.Employees _
&lt;span style="color: blue"&gt;    On &lt;/span&gt;Order.EmployeeID &lt;span style="color: blue"&gt;Equals &lt;/span&gt;Employee.EmployeeID _
&lt;span style="color: blue"&gt;  Where &lt;/span&gt;Order.OrderDate &lt;span style="color: blue"&gt;IsNot Nothing AndAlso &lt;/span&gt;_
    Order.ShippedDate &lt;span style="color: blue"&gt;IsNot Nothing AndAlso &lt;/span&gt;_
    Order.ShippedDate.Value.Date &amp;gt;= #1/1/1998# _
&lt;span style="color: blue"&gt;  Let &lt;/span&gt;DateOrder = Order.OrderDate.Value.ToShortDateString _
&lt;span style="color: blue"&gt;  Let &lt;/span&gt;DateShip = Order.ShippedDate.Value.ToShortDateString _
&lt;span style="color: blue"&gt;  Select New &lt;/span&gt;Letter &lt;span style="color: blue"&gt;With &lt;/span&gt;{ _
    .CustomerID = Order.CustomerID, _&lt;br&gt;    &lt;strong&gt;.OrderID = Order.OrderID, _
&lt;br&gt;&lt;br&gt;&lt;br&gt;    .EmployeePhoto = &lt;span style="color: blue"&gt;If&lt;/span&gt;(Employee.Photo &lt;span style="color: blue"&gt;IsNot Nothing&lt;/span&gt;, Employee.Photo.ToArray, &lt;span style="color: blue"&gt;Nothing&lt;/span&gt;), _&lt;/strong&gt;
    .Document = &lt;span style="color: #6464b9"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #844646"&gt;xml &lt;/span&gt;&lt;span style="color: #b96464"&gt;version&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;1.0&lt;/span&gt;&lt;span style="color: #555555"&gt;" &lt;/span&gt;&lt;span style="color: #b96464"&gt;encoding&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;utf-8&lt;/span&gt;&lt;span style="color: #555555"&gt;" &lt;/span&gt;&lt;span style="color: #b96464"&gt;standalone&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;yes&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;?&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:document ... &lt;br&gt;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;            &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:body&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt; ...
&lt;/span&gt;&lt;span style="color: #6464b9"&gt;                &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:p &lt;/span&gt;&lt;span style="color: #b96464"&gt;w:rsidR&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;00A9498E&lt;/span&gt;&lt;span style="color: #555555"&gt;" &lt;/span&gt;&lt;span style="color: #b96464"&gt;w:rsidRDefault&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;00A9498E&lt;/span&gt;&lt;span style="color: #555555"&gt;" &lt;/span&gt;&lt;span style="color: #b96464"&gt;w:rsidP&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;00AA2EC6&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:r&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:t &lt;/span&gt;&lt;span style="color: #b96464"&gt;xml:space&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;preserve&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #555555"&gt;If you have any issues please contact &lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;w:t&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                    &amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;w:r&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:proofErr &lt;/span&gt;&lt;span style="color: #b96464"&gt;w:type&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;spellStart&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;/&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:r&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:t&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: #fffebf; color: #555555"&gt;&amp;lt;%=&lt;/span&gt; Employee.FirstName &amp;amp; &lt;span style="color: #a31515"&gt;" " &lt;/span&gt;&amp;amp; Employee.LastName &lt;span style="background: #fffebf; color: #555555"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;w:t&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                    &amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;w:r&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:proofErr &lt;/span&gt;&lt;span style="color: #b96464"&gt;w:type&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;spellEnd&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;/&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:r&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                            &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:t &lt;/span&gt;&lt;span style="color: #b96464"&gt;xml:space&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;preserve&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt; &lt;/span&gt;&lt;span style="color: #555555"&gt;at&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;w:t&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                        &amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;w:r&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:r &lt;/span&gt;&lt;span style="color: #b96464"&gt;w:rsidR&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;005F35D6&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                            &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:t &lt;/span&gt;&lt;span style="color: #b96464"&gt;xml:space&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;preserve&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt; &lt;/span&gt;&lt;span style="color: #555555"&gt;ext.&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;w:t&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                        &amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;w:r&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:r&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                            &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:t &lt;/span&gt;&lt;span style="color: #b96464"&gt;xml:space&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;preserve&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;w:t&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                        &amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;w:r&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                        &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:r &lt;/span&gt;&lt;span style="color: #b96464"&gt;w:rsidR&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;005F35D6&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                            &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:t&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: #fffebf; color: #555555"&gt;&amp;lt;%=&lt;/span&gt; Employee.Extension &lt;span style="background: #fffebf; color: #555555"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;w:t&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                        &amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;w:r&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                        &amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;w:p&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt; ...
                        &lt;/span&gt;&lt;strong&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:drawing&lt;/span&gt;&lt;/strong&gt;&lt;strong&gt;&lt;span style="color: #6464b9"&gt;&amp;gt; ...
&lt;/span&gt;&lt;span style="color: #6464b9"&gt;                            &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;pic:blipFill&lt;/span&gt;&lt;/strong&gt;&lt;strong&gt;&lt;span style="color: #6464b9"&gt;&amp;gt; ...
                                &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;a:blip &lt;/span&gt;&lt;span style="color: #b96464"&gt;r:embed&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="background: #fffebf; color: #555555"&gt;&amp;lt;%=&lt;/span&gt; &lt;/strong&gt;&lt;span style="color: #a31515"&gt;"rId" &lt;/span&gt;&amp;amp; &lt;strong&gt;Order.OrderID &lt;span style="background: #fffebf; color: #555555"&gt;%&amp;gt;&lt;/span&gt;&lt;/strong&gt;&lt;strong&gt;&lt;span style="color: #6464b9"&gt;/&amp;gt; ...
&lt;/span&gt;&lt;span style="color: #6464b9"&gt;                        &amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;w:drawing&lt;/span&gt;&lt;/strong&gt;&lt;strong&gt;&lt;span style="color: #6464b9"&gt;&amp;gt; ...
&lt;/span&gt;&lt;span style="color: #6464b9"&gt;                        &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:p &lt;/span&gt;&lt;span style="color: #b96464"&gt;w:rsidR&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;00622A50&lt;/span&gt;&lt;span style="color: #555555"&gt;" &lt;/span&gt;&lt;span style="color: #b96464"&gt;w:rsidRDefault&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;00622A50&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;/strong&gt;&lt;strong&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                            &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:r&lt;/span&gt;&lt;/strong&gt;&lt;strong&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                                &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;w:br &lt;/span&gt;&lt;span style="color: #b96464"&gt;w:type&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;span style="color: #6464b9"&gt;page&lt;/span&gt;&lt;span style="color: #555555"&gt;"&lt;/span&gt;&lt;/strong&gt;&lt;strong&gt;&lt;span style="color: #6464b9"&gt;/&amp;gt;
                            &amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;w:r&lt;/span&gt;&lt;/strong&gt;&lt;strong&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                        &amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;w:p&lt;/span&gt;&lt;/strong&gt;&lt;span style="color: #6464b9"&gt;&lt;strong&gt;&amp;gt; ...&lt;/strong&gt;
&lt;/span&gt;&lt;span style="color: #6464b9"&gt;                    &amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;w:body&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
                &amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;w:document&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;}&lt;/pre&gt;
&lt;p&gt;The query returns an IEnumerable(Of Letter) objects with the Document property set to the document.xml data for that customer and the EmployeePhoto set to the photo byte array. If we wanted to create separate documents (which is exactly what I demonstrated in my &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" target="_blank"&gt;DevProConnections article&lt;/a&gt;) it’s actually pretty simple because all we need to do is copy the template and then replace the document.xml and the image data, we don’t have to mess with the relationship ID at all. However if we want to create a single document with all our letters we need to delete the placeholder image part and add new unique image parts for the Letter.EmployeePhoto. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Adding and Linking the Images into a Single Word Document&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Because relationship IDs must be unique in a document I used the OrderID as the embedded expression for the r:embed attribute in the XML Literal above. You can choose to use any unique ID you want but it must start with an alpha character, that’s why I prefixed it with “rId”. When you use the Open XML SDK to add the new image parts we have to specify the relationship ID to use. To update the code we wrote yesterday to work with the Open XML SDK and also work with images we first need to add a call to open the Word document template, grab the main document part and then delete the image part by calling DeletePart:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: green"&gt;'Place the letters in a separate directory
&lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;sourceFile = CurDir() &amp;amp; &lt;span style="color: #a31515"&gt;"\LetterTemplate.docx"
&lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;letterDir = CurDir() &amp;amp; &lt;span style="color: #a31515"&gt;"\Letters\"
&lt;/span&gt;&lt;span style="color: blue"&gt;My&lt;/span&gt;.Computer.FileSystem.CreateDirectory(letterDir)

&lt;span style="color: blue"&gt;Dim &lt;/span&gt;mergeFile = letterDir &amp;amp; &lt;span style="color: #a31515"&gt;"AllLetters.docx"
&lt;/span&gt;&lt;span style="color: blue"&gt;My&lt;/span&gt;.Computer.FileSystem.CopyFile(sourceFile, mergeFile, &lt;span style="color: blue"&gt;True&lt;/span&gt;)

&lt;span style="color: green"&gt;'Open the Document template using the Open XML SDK
&lt;/span&gt;&lt;span style="color: blue"&gt;Using &lt;/span&gt;wordDoc = WordprocessingDocument.Open(mergeFile, &lt;span style="color: blue"&gt;True&lt;/span&gt;)

&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: green"&gt;'Delete the placeholder image from the template so we can replace it with the real photos
    &lt;/span&gt;mainPart.DeletePart(&lt;span style="color: #a31515"&gt;"rId4"&lt;/span&gt;)&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;This opens the Word document as read/write and then deletes the placeholder image. You should also notice at this point that the code is a bit simpler to open the package than yesterday because we don’t have to declare the relative URI’s or content types. The Open XML SDK helps us here. Next we need to load the document.xml into an XElement object and grab the body:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;    Dim &lt;/span&gt;mainDocumentXML &lt;span style="color: blue"&gt;As &lt;/span&gt;XElement
    &lt;span style="color: blue"&gt;Using &lt;/span&gt;sr &lt;span style="color: blue"&gt;As New &lt;/span&gt;StreamReader(mainPart.GetStream)
        mainDocumentXML = XElement.Load(sr)
    &lt;span style="color: blue"&gt;End Using

    Dim &lt;/span&gt;mainBody = mainDocumentXML...&lt;span style="color: #6464b9"&gt;&amp;lt;&lt;/span&gt;w:body&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;.First()
    &lt;span style="color: blue"&gt;Dim &lt;/span&gt;i = 0&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;Now we can loop through all the letters, grab the body of those XDocuments and then add an image part. We need to specify the content type and the relationship ID that must match what we embedded in the XML Literal in our query. Then we can either replace the main document body with the first letter (overwrite our placeholder data) otherwise we append the rest of the letter contents into the document:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;    For Each &lt;/span&gt;letter &lt;span style="color: blue"&gt;In &lt;/span&gt;letters
        &lt;span style="color: blue"&gt;Dim &lt;/span&gt;nextBody = letter.Document...&lt;span style="color: #6464b9"&gt;&amp;lt;&lt;/span&gt;w:body&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;.First()
        &lt;span&gt;'Add the new imagePart. The SDK takes care of linking this properly.
       &lt;strong&gt; Dim &lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;imagePart = mainPart.AddImagePart(&lt;span style="color: #a31515"&gt;"image/png"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"rId" &lt;/span&gt;&amp;amp; letter.OrderID)&lt;/strong&gt;

        &lt;span style="color: blue"&gt;If &lt;/span&gt;i = 0 &lt;span style="color: blue"&gt;Then
           &lt;/span&gt;&lt;span style="color: green"&gt;'Replace the first body contents in the template
           &lt;/span&gt;mainBody.ReplaceNodes(nextBody.Elements())
        &lt;span style="color: blue"&gt;Else
           &lt;/span&gt;&lt;span style="color: green"&gt;'Otherwise append the next letter contents
           &lt;/span&gt;mainBody.Add(nextBody.Elements())
        &lt;span style="color: blue"&gt;End If&lt;/span&gt;&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;Next we need to feed the byte array data into the ImagePart. Note that since I’m using Northwind for this example there is an OLE header on those images that we must strip off that is 78 bytes. If you are using your own images stored in SQL Server you won’t have to do that:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: green"&gt;        'Now feed the byte array into the ImagePart
        &lt;/span&gt;&lt;span style="color: blue"&gt;If &lt;/span&gt;letter.EmployeePhoto &lt;span style="color: blue"&gt;IsNot Nothing Then
            &lt;/span&gt;&lt;span style="color: green"&gt;'Using ms As New System.IO.MemoryStream(letter.EmployeePhoto.ToArray)
            'NOTE: Northwind Photos have an OLE header on them that we must strip off.
            ' You don't have to do this if you are using your own SQL-server stored images
            &lt;/span&gt;&lt;span style="color: blue"&gt;Using &lt;/span&gt;ms &lt;span style="color: blue"&gt;As New &lt;/span&gt;System.IO.MemoryStream(letter.EmployeePhoto, 78, _
                                                   letter.EmployeePhoto.Length - 78)
                imagePart.FeedData(ms)
            &lt;span style="color: blue"&gt;End Using
        End If

        &lt;/span&gt;i += 1
    &lt;span style="color: blue"&gt;Next&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Now that we’ve built up the document XML, added our image parts and linked them properly, the final step is to replace the document part with our XML just like before:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: green"&gt;    'Replace the document part with our XML
    &lt;/span&gt;&lt;span style="color: blue"&gt;Using &lt;/span&gt;sw &lt;span style="color: blue"&gt;As New &lt;/span&gt;StreamWriter(mainPart.GetStream(FileMode.Create))
        mainDocumentXML.Save(sw)
    &lt;span style="color: blue"&gt;End Using

End Using&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Now when we run the application you will see a single document with all the letters, including photos, that’s much easier to print than multiple files. &lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MergingTextPhotosintoaSingleWordDocument_E6F4/image_12.png" target="_blank"&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/MergingTextPhotosintoaSingleWordDocument_E6F4/image_thumb_5.png" width="687" height="255"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;There’s Always Room for Improvement&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;LINQ &amp;amp; Northwind savvy folks may notice that I’m actually creating duplicates of the employee photos. Since I’m flattening out the data in my query to have 1 photo per order there could be an unnecessary amount of duplicate images. This can cause the document to get bloated. To be more efficient we should reuse the relationship ID’s to the images if they are the same on multiple orders. One approach would be to modify the LINQ query and Letter object to select the EmployeePhoto and then have a collection of order &amp;amp; document data under that. I’ll leave that experiment up to you :-)&lt;/p&gt;
&lt;p&gt;&lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=openxmlvb&amp;amp;DownloadId=7325" target="_blank"&gt;Take a look at the full code listing for this example&lt;/a&gt; as well as the &lt;a href="http://code.msdn.microsoft.com/openxmlvb" target="_blank"&gt;complete project with other Open XML examples here on Code Gallery&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9899172" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bethmassi/archive/tags/LINQ/default.aspx">LINQ</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/VSTO/default.aspx">VSTO</category></item><item><title>Mail Merging Into a Single Word Document Using XML Literals</title><link>http://blogs.msdn.com/bethmassi/archive/2009/09/23/mail-merging-into-a-single-word-document-using-xml-literals.aspx</link><pubDate>Thu, 24 Sep 2009 02:18:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9898711</guid><dc:creator>Beth Massi</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9898711.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9898711</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9898711</wfw:comment><description>&lt;P&gt;With the release of Microsoft Office 2007 we can work with a much simpler, standard, XML format called &lt;A href="http://www.ecma-international.org/publications/standards/Ecma-376.htm" target=_blank mce_href="http://www.ecma-international.org/publications/standards/Ecma-376.htm"&gt;Open XML&lt;/A&gt; which opens the door for many types of applications that cannot work via COM. What if you needed to build a scalable web service that processes many documents in high volume? What if you wanted to quickly read or write to these formats from a client application but wanted to have minimal dependencies on other applications? These types of programs do not want to require Microsoft Office be installed to run. The cool thing is you have the tools already with Visual Basic 2008. XML Literals are an easy way to manipulate any kind of XML, including Open XML.&lt;/P&gt;
&lt;P&gt;I’ve written before on how to use XML Literals to manipulate Word documents, if you missed them:&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" mce_href="http://blogs.msdn.com/bethmassi/archive/2009/08/17/devproconnections-article-taking-advantage-of-linq-and-xml-in-microsoft-office-2007.aspx"&gt;&lt;STRONG&gt;DevProConnections Article: Taking Advantage of LINQ and XML in Microsoft Office 2007&lt;/STRONG&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;Sample: &lt;A href="http://code.msdn.microsoft.com/openxmlvb" mce_href="http://code.msdn.microsoft.com/openxmlvb"&gt;Working with Open XML in Visual Basic&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/2008/07/30/accessing-openxml-document-parts-with-the-openxml-sdk.aspx" mce_href="http://blogs.msdn.com/bethmassi/archive/2008/07/30/accessing-openxml-document-parts-with-the-openxml-sdk.aspx"&gt;Accessing Open XML Document Parts with the Open XML SDK&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/bethmassi/archive/2007/12/06/mail-merging-with-word-and-linq-to-xml-in-vb.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2007/12/06/mail-merging-with-word-and-linq-to-xml-in-vb.aspx"&gt;Mail Merging with Word, LINQ and XML Literals in VB&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;If you aren’t familiar with XML Literals or Open XML then I’d suggest reading the article &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" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2009/08/17/devproconnections-article-taking-advantage-of-linq-and-xml-in-microsoft-office-2007.aspx"&gt;in the first bullet above&lt;/A&gt; first. It’s a great intro into XML Literals, Open XML and it also demonstrates a couple practical ways of reading and writing to Word document formats directly. &lt;/P&gt;
&lt;P&gt;Recently I got a great question on how to change the program outlined in the &lt;A href="http://blogs.msdn.com/bethmassi/archive/2007/12/06/mail-merging-with-word-and-linq-to-xml-in-vb.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2007/12/06/mail-merging-with-word-and-linq-to-xml-in-vb.aspx"&gt;last bullet above&lt;/A&gt; to merge letters we were creating on the fly from a database into a single document instead of multiple documents like we’re doing. This would make it much easier for an end user to print them. That’s such an obvious thing I can’t believe I didn’t think of that! For those of you that aren’t familiar with what we did I’ll give a quick recap of that application. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Creating Word Documents with XML Literals&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;What I wanted to do is take all the Customers in the Northwind database who had some orders shipping today and send them thank you letters. To get started I created a new Word 2007 document with the letter text and some placeholder field names to indicate where I want the data:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MailMergingaSingleWordDocumentUsingXMLLi_C84D/image_6.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MailMergingaSingleWordDocumentUsingXMLLi_C84D/image_6.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/MailMergingaSingleWordDocumentUsingXMLLi_C84D/image_thumb_2.png" width=687 height=385 mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MailMergingaSingleWordDocumentUsingXMLLi_C84D/image_thumb_2.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Save the document (I named it Doc1.docx) and then rename the .docx extension to .zip and you can drill into the package and see a bunch of XML documents inside it. If we drill down through the zip file we'll see that the text we just typed is located in the \word\document.xml file. Copy this xml and paste it into the Visual Basic editor, it will infer it as an XDocument object, and then you can use embedded expressions to replace the placeholders. (If I’ve lost you, &lt;A href="http://blogs.msdn.com/bethmassi/archive/2007/12/06/mail-merging-with-word-and-linq-to-xml-in-vb.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2007/12/06/mail-merging-with-word-and-linq-to-xml-in-vb.aspx"&gt;read this article which explains it step-by-step&lt;/A&gt;.)&lt;/P&gt;
&lt;P&gt;In order to create letters for our customers in the database, we want to end up with a collection of XDocuments with our data merged into them. I created a simple class called Letter that has two properties, CustomerID As String and Document As XDocument. Then I wrote a LINQ query to select the data and embed it into the document (I’ve omitted all the WordProcessingML for clarity, take a loot at &lt;A href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=openxmlvb&amp;amp;DownloadId=7325" target=_blank mce_href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=openxmlvb&amp;amp;DownloadId=7325"&gt;the code sample&lt;/A&gt; for the whole listing.)&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;letters = _
&lt;SPAN style="COLOR: blue"&gt;    From &lt;/SPAN&gt;Order &lt;SPAN style="COLOR: blue"&gt;In &lt;/SPAN&gt;db.Orders _
&lt;SPAN style="COLOR: blue"&gt;    Join &lt;/SPAN&gt;Employee &lt;SPAN style="COLOR: blue"&gt;In &lt;/SPAN&gt;db.Employees _
&lt;SPAN style="COLOR: blue"&gt;        On &lt;/SPAN&gt;Order.EmployeeID &lt;SPAN style="COLOR: blue"&gt;Equals &lt;/SPAN&gt;Employee.EmployeeID _
&lt;SPAN style="COLOR: blue"&gt;    Where &lt;/SPAN&gt;Order.OrderDate &lt;SPAN style="COLOR: blue"&gt;IsNot Nothing AndAlso &lt;/SPAN&gt;_
        Order.ShippedDate &lt;SPAN style="COLOR: blue"&gt;IsNot Nothing AndAlso &lt;/SPAN&gt;_
        Order.ShippedDate.Value.Date &amp;gt;= #1/1/2007# _
&lt;SPAN style="COLOR: blue"&gt;    Let &lt;/SPAN&gt;DateOrder = Order.OrderDate.Value.ToShortDateString _
&lt;SPAN style="COLOR: blue"&gt;    Let &lt;/SPAN&gt;DateShip = Order.ShippedDate.Value.ToShortDateString _
&lt;SPAN style="COLOR: blue"&gt;    Select New &lt;/SPAN&gt;Letter &lt;SPAN style="COLOR: blue"&gt;With &lt;/SPAN&gt;{ _
        .CustomerID = Order.Customer.CustomerID, _
        .Document = &lt;SPAN style="COLOR: #6464b9"&gt;&amp;lt;?&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;xml &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;version&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;1.0&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;" &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;encoding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;utf-8&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;" &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;standalone&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;yes&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;?&amp;gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:document &lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;...&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:p &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;w:rsidR&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;00705CFF&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;" &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;w:rsidRDefault&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;00112228&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;" &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;w:rsidP&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;00AA2EC6&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:r&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:br&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;/&amp;gt;
        &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:r&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:r &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;w:rsidR&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;007A5236&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:t &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;xml:space&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;preserve&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;Dear &lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:t&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
        &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:r&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:proofErr &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;w:type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;spellStart&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;/&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:r&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:t&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="BACKGROUND: #fffebf; COLOR: #555555"&gt;&amp;lt;%=&lt;/SPAN&gt; Order.Customer.ContactName &lt;SPAN style="BACKGROUND: #fffebf; COLOR: #555555"&gt;%&amp;gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:t&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
        &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:r&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:proofErr &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;w:type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;spellEnd&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;/&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:r &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;w:rsidR&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;00AA2EC6&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
                &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:t&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;,&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:t&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
            &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:r&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
     &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:p&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;     &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:p &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;w:rsidR&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;00E04FB0&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;" &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;w:rsidRDefault&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;00AA2EC6&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;" &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;w:rsidP&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;00AA2EC6&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:r&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:t &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;xml:space&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;preserve&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;We’d like to inform you that the order you placed on &lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:t&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
        &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:r&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:proofErr &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;w:type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;spellStart&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;/&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:r &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;w:rsidR&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;00112228&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
                &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:t&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="BACKGROUND: #fffebf; COLOR: #555555"&gt;&amp;lt;%=&lt;/SPAN&gt; DateOrder &lt;SPAN style="BACKGROUND: #fffebf; COLOR: #555555"&gt;%&amp;gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:t&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
            &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:r&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:proofErr &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;w:type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;spellEnd&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;/&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:r &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;w:rsidR&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;00806521&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
                &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:t &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;xml:space&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;preserve&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;has shipped on &lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:t&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
            &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:r&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:proofErr &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;w:type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;spellStart&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;/&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:r &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;w:rsidR&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;00112228&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
                &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:t&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="BACKGROUND: #fffebf; COLOR: #555555"&gt;&amp;lt;%=&lt;/SPAN&gt; DateShip &lt;SPAN style="BACKGROUND: #fffebf; COLOR: #555555"&gt;%&amp;gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:t&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
            &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:r&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
... &lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:document&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" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;The query returns an IEnumerable(Of Letter) objects with the Document property set to the document.xml data for that customer. The next step involved taking the template Doc1.docx file, making a copy of it and then simply replacing the document.xml part inside the package with the one here in the Letter class for each letter. However, what I did was create separate letters for each customer. Instead we want to create one .docx file with &lt;STRONG&gt;ALL&lt;/STRONG&gt; the letter data merged inside. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Merging into a Single Word Document&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The first thing we need to do is insert a page break between all our letters. The easiest thing to do is to open back up your template Doc1.docx file in Word and insert a page break, save it, and then look at the document.xml again in the package. You should see this WordProccessingML element inserted near the end:&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:p &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;w:rsidR&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;00622A50&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;" &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;w:rsidRDefault&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;00622A50&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:r&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:br &lt;/SPAN&gt;&lt;SPAN style="COLOR: #b96464"&gt;w:type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;page&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;/&amp;gt;
    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:r&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:p&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" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;Paste this into the query above in the document exactly where you pulled it out of the document.xml. &lt;/P&gt;
&lt;P&gt;Next we have a couple options on how to manipulate the package (docx file). I’ve shown &lt;A href="http://blogs.msdn.com/bethmassi/archive/2008/07/30/accessing-openxml-document-parts-with-the-openxml-sdk.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/2008/07/30/accessing-openxml-document-parts-with-the-openxml-sdk.aspx"&gt;how to use the Open XML SDK before to manipulate documents&lt;/A&gt; but in this simple case we can use the System.IO.Packaging classes directly. This is because all we’re doing is working with text in the document. If we were working with images or embedded objects it would be easier to use the SDK. In the next post we’ll add photos of the employees on each order into the document, but for this post let’s just focus on how to merge the text. &lt;/P&gt;
&lt;P&gt;So the first thing we need to do is Import some namespaces including an XML namespace that we’re going to use:&lt;/P&gt;&lt;PRE class=code&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:w&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;http://schemas.openxmlformats.org/wordprocessingml/2006/main&lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Imports &lt;/SPAN&gt;System.IO
&lt;SPAN style="COLOR: blue"&gt;Imports &lt;/SPAN&gt;System.IO.Packaging&lt;/PRE&gt;
&lt;P&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;Next we need to set up some variables and copy the Doc1.docx template to a new file I’m calling AllLetters.docx.&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;uri &lt;SPAN style="COLOR: blue"&gt;As New &lt;/SPAN&gt;Uri(&lt;SPAN style="COLOR: #a31515"&gt;"/word/document.xml"&lt;/SPAN&gt;, UriKind.Relative)
&lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;contentType = &lt;SPAN style="COLOR: #a31515"&gt;"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;sourceFile = CurDir() &amp;amp; &lt;SPAN style="COLOR: #a31515"&gt;"\Doc1.docx"
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;letterDir = CurDir() &amp;amp; &lt;SPAN style="COLOR: #a31515"&gt;"\Letters\"
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;My&lt;/SPAN&gt;.Computer.FileSystem.CreateDirectory(letterDir)

&lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;mergeFile = letterDir &amp;amp; &lt;SPAN style="COLOR: #a31515"&gt;"AllLetters.docx"
&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;My&lt;/SPAN&gt;.Computer.FileSystem.CopyFile(sourceFile, mergeFile, &lt;SPAN style="COLOR: blue"&gt;True&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;Now we can open the template package and load the main document part as an XElement:&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Using &lt;/SPAN&gt;p &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;Package = Package.Open(mergeFile)

&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 = p.GetPart(uri)
    &lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;mainDocumentXML &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;XElement&lt;BR&gt;
&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;    &lt;SPAN style="COLOR: blue"&gt;Using &lt;/SPAN&gt;sr &lt;SPAN style="COLOR: blue"&gt;As New &lt;/SPAN&gt;StreamReader(mainPart.GetStream)
        mainDocumentXML = XElement.Load(sr)
    &lt;SPAN style="COLOR: blue"&gt;End Using&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 next part is where it gets fun. A word document has a top element structure like this:&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:document&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:body&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
       &lt;/SPAN&gt;&lt;SPAN style="COLOR: #555555"&gt;...
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:body&lt;/SPAN&gt;&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #844646"&gt;w:document&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" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;So what we need to do is grab the body of the template, replace it with the first customer’s document body we have and then append the rest of the elements inside the bodies of the rest of the documents. A word document can only have one &amp;lt;w:body&amp;gt; element for it to be legal. The way we get the &amp;lt;w:body&amp;gt; XElement from the document is using the descendants syntax with the three dot notation (…): &lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;    Dim &lt;/SPAN&gt;mainBody = mainDocumentXML...&lt;SPAN style="COLOR: #6464b9"&gt;&amp;lt;&lt;/SPAN&gt;w:body&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;&lt;/SPAN&gt;.First()
    &lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;i = 0

    &lt;SPAN style="COLOR: blue"&gt;For Each &lt;/SPAN&gt;letter &lt;SPAN style="COLOR: blue"&gt;In &lt;/SPAN&gt;letters
        &lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;nextBody = letter.Document...&lt;SPAN style="COLOR: #6464b9"&gt;&amp;lt;&lt;/SPAN&gt;w:body&lt;SPAN style="COLOR: #6464b9"&gt;&amp;gt;&lt;/SPAN&gt;.First()
        &lt;SPAN style="COLOR: blue"&gt;If &lt;/SPAN&gt;i = 0 &lt;SPAN style="COLOR: blue"&gt;Then
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;'Replace the first body contents in the template
            &lt;/SPAN&gt;mainBody.ReplaceNodes(nextBody.Elements())
        &lt;SPAN style="COLOR: blue"&gt;Else
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;'Append the new contents for the rest of the customers
            &lt;/SPAN&gt;mainBody.Add(nextBody.Elements())
        &lt;SPAN style="COLOR: blue"&gt;End If
        &lt;/SPAN&gt;i += 1
    &lt;SPAN style="COLOR: blue"&gt;Next&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Now that we’ve built up the right body with all our letter data in it, we can replace the main document.xml part in the package and close it.&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: green"&gt;    'Delete the current document.xml file in the template
    &lt;/SPAN&gt;p.DeletePart(uri)
    &lt;SPAN style="COLOR: green"&gt;'Replace that part with our new merged XDocument
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;replace &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;PackagePart = p.CreatePart(uri, contentType)&lt;BR&gt;
    &lt;SPAN style="COLOR: blue"&gt;Using &lt;/SPAN&gt;sw &lt;SPAN style="COLOR: blue"&gt;As New &lt;/SPAN&gt;StreamWriter(replace.GetStream())
        mainDocumentXML.Save(sw)
        sw.Close()
    &lt;SPAN style="COLOR: blue"&gt;End Using

&lt;/SPAN&gt;    p.Close()
&lt;SPAN style="COLOR: blue"&gt;End Using&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;Now when we run this, all the letters will be mail merged into the same document for easy printing:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MailMergingaSingleWordDocumentUsingXMLLi_C84D/image_4.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MailMergingaSingleWordDocumentUsingXMLLi_C84D/image_4.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/MailMergingaSingleWordDocumentUsingXMLLi_C84D/image_thumb_1.png" width=703 height=253 mce_src="http://blogs.msdn.com/blogfiles/bethmassi/WindowsLiveWriter/MailMergingaSingleWordDocumentUsingXMLLi_C84D/image_thumb_1.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;As I mentioned if we have embedded images or objects that we need to replace it gets a little trickier. In the &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" mce_href="http://blogs.msdn.com/bethmassi/archive/2009/08/17/devproconnections-article-taking-advantage-of-linq-and-xml-in-microsoft-office-2007.aspx"&gt;DevProConnections Article&lt;/A&gt; I have an example of how to create multiple documents with embedded pictures of the employee’s photo. In the next post I’ll show you how 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 mce_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; to create a single document with embedded pictures as well. &lt;/P&gt;
&lt;P&gt;Until then, have a look &lt;A href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=openxmlvb&amp;amp;DownloadId=7325" target=_blank mce_href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=openxmlvb&amp;amp;DownloadId=7325"&gt;at the complete code I put up on Code Gallery&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;[UPDATE:&amp;nbsp;&lt;A href="http://blogs.msdn.com/bethmassi/archive/2009/09/24/merging-text-photos-into-a-word-document-using-open-xml-sdk.aspx" mce_href="http://blogs.msdn.com/bethmassi/archive/2009/09/24/merging-text-photos-into-a-word-document-using-open-xml-sdk.aspx"&gt;Merging Text &lt;STRONG&gt;&amp;amp; Photos &lt;/STRONG&gt;into a Word Document using Open XML SDK&lt;/A&gt;]&lt;/P&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9898711" 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/LINQ/default.aspx">LINQ</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></item><item><title>DevProConnections Article: Taking Advantage of LINQ and XML in Microsoft Office 2007</title><link>http://blogs.msdn.com/bethmassi/archive/2009/08/17/devproconnections-article-taking-advantage-of-linq-and-xml-in-microsoft-office-2007.aspx</link><pubDate>Mon, 17 Aug 2009 20:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9879123</guid><dc:creator>Beth Massi</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9879123.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9879123</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9879123</wfw:comment><description>&lt;p&gt;This month I have an article on DevProConnections:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;a href="http://www.devproconnections.com/tabId/180/itemId/4575/Taking-Advantage-of-LINQ-and-XML-in-Microsoft-Offi.aspx" target="_blank"&gt;Taking Advantage of LINQ and XML in Microsoft Office 2007&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;In this article, I talk about how a lot of applications that need to take advantage of Microsoft Office can do so without going through COM. Many programs that need to process documents often require manipulation of the file formats directly and doing that through the Office component object model won’t scale very well. It also requires that Microsoft Office be installed to run. A better route in a lot of these cases is to 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;. With the release of Office 2007, Word documents, Excel spreadsheets and PowerPoint presentations are based on an open standard for packaging XML files called Open XML. Using Visual Basic’s powerful and simple implementation of LINQ to XML you can work with these new document formats much easier than ever before.&lt;/p&gt;  &lt;p&gt;I show a couple practical examples of reading data from Word documents and updating a database as well as reading data from a database to create Word documents – all without COM. No Office applications need to be installed in order to read and write to these formats directly.&amp;#160; &lt;/p&gt;  &lt;p&gt;This article is based on the two episodes I did on DnrTV:&lt;/p&gt;  &lt;ul&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;dnrTV: 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;dnrTV: More Fun with Office and XML Literals&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;[UPDATE: Here's code samples (also includes a presentation pptx)] &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&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;More resources:&lt;/p&gt;  &lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c6e744e5-36e9-45f5-8d8c-331df206e0d0&amp;amp;DisplayLang=en"&gt;Open XML Format SDK 2.0&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/office/bb265236.aspx"&gt;Open XML Resource Center&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=46B6BF86-E35D-4870-B214-4D7B72B02BF9&amp;amp;displaylang=en"&gt;Microsoft Visual Studio Tools for the Office System Power Tools v1.0.0.0&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;a href="http://www.codeplex.com/dbe"&gt;Word 2007 Content Control Toolkit &lt;/a&gt;&lt;/li&gt;  &lt;li&gt;&lt;a href="http://msdn.com/vsto"&gt;VSTO Developer Center&lt;/a&gt; &lt;/li&gt;  &lt;li&gt;&lt;a href="http://msdn.com/vbasic"&gt;Visual Basic Developer Center&lt;/a&gt;     &lt;p&gt;Enjoy!&lt;/p&gt;    &lt;p&gt;&lt;/p&gt; &lt;/li&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9879123" 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/LINQ/default.aspx">LINQ</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></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>Community Article: Automate Common Office Tasks</title><link>http://blogs.msdn.com/bethmassi/archive/2009/06/25/community-article-automate-common-office-tasks.aspx</link><pubDate>Fri, 26 Jun 2009 01:34:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9804418</guid><dc:creator>Beth Massi</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9804418.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9804418</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9804418</wfw:comment><description>&lt;p&gt;If you haven’t seen it yet, we’ve got &lt;a href="http://msdn.microsoft.com/en-us/vsto/dd935909.aspx" target="_blank"&gt;a new article&lt;/a&gt; from &lt;a href="https://mvp.support.microsoft.com/profile=169AE602-45EF-47E6-8868-CA3E91D0A1EE"&gt;Robert Green&lt;/a&gt; (VSTO MVP) up on the &lt;a href="http://msdn.microsoft.com/en-us/vbasic/default.aspx" target="_blank"&gt;Visual Basic&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/vsto/default.aspx" target="_blank"&gt;VSTO Dev Centers&lt;/a&gt;. In this article, learn how you can use Visual Basic to build application-level add-ins that automate common Microsoft Office tasks. It’s a good introduction to Office development with Visual Studio so check it out!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/vsto/dd935909.aspx" target="_blank"&gt;&lt;strong&gt;Create an Application-Level Add-In to Automate Common Office Tasks&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9804418" 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/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></item><item><title>Getting a Count of Unread Email in Outlook</title><link>http://blogs.msdn.com/bethmassi/archive/2009/04/28/getting-a-count-of-unread-email-in-outlook.aspx</link><pubDate>Tue, 28 Apr 2009 19:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9572819</guid><dc:creator>Beth Massi</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9572819.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9572819</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9572819</wfw:comment><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/bethmassi/archive/2009/04/27/tally-rows-in-a-dataset-that-match-a-condition.aspx" target="_blank"&gt;Last post I was talking about DataSets and aggregating data with LINQ&lt;/a&gt; and the example I gave was around finding rows of data where the Status = “Unread”. This got me thinking about how we could do this by asking Outlook for my unread email count – one of the programs I spend a lot of time in ;-). This actually is a pretty easy thing to do if you use the Primary Interop Assembly (PIA) for Outlook – Microsoft.Office.Interop.Outlook. Add a reference to your project and then import the namespace at the top of your program. &lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;Microsoft.Office.Interop.Outlook&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Then you can write the following code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;OutlookApp &lt;span style="color: blue"&gt;As New &lt;/span&gt;Application()
&lt;span style="color: blue"&gt;Dim &lt;/span&gt;myMail &lt;span style="color: blue"&gt;As &lt;/span&gt;[NameSpace] = OutlookApp.GetNamespace(&lt;span style="color: #a31515"&gt;&amp;quot;MAPI&amp;quot;&lt;/span&gt;)

myMail.Logon(ShowDialog:=&lt;span style="color: blue"&gt;True&lt;/span&gt;, NewSession:=&lt;span style="color: blue"&gt;False&lt;/span&gt;)
&lt;span style="color: blue"&gt;Dim &lt;/span&gt;count &lt;span style="color: blue"&gt;As Integer &lt;/span&gt;= myMail.GetDefaultFolder(OlDefaultFolders.olFolderInbox).UnReadItemCount&lt;/pre&gt;

&lt;p&gt;Note that if you have selected an Outlook Add-in project template in Visual Studio then you already have reference to the Application and you’re already logged in so the code is even simpler:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;myMail &lt;span style="color: blue"&gt;As &lt;/span&gt;[NameSpace] = &lt;span style="color: blue"&gt;Me&lt;/span&gt;.Application.GetNamespace(&lt;span style="color: #a31515"&gt;&amp;quot;MAPI&amp;quot;&lt;/span&gt;)
&lt;span style="color: blue"&gt;Dim &lt;/span&gt;unread &lt;span style="color: blue"&gt;As Integer &lt;/span&gt;= myMail.GetDefaultFolder(OlDefaultFolders.olFolderInbox).UnReadItemCount&lt;/pre&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9572819" 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/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/VSTO/default.aspx">VSTO</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>dnrTV: Showing off the Open XML SDK and LINQ</title><link>http://blogs.msdn.com/bethmassi/archive/2009/04/07/dnrtv-showing-off-the-open-xml-sdk-and-linq.aspx</link><pubDate>Wed, 08 Apr 2009 01:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9536792</guid><dc:creator>Beth Massi</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/bethmassi/comments/9536792.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bethmassi/commentrss.aspx?PostID=9536792</wfw:commentRss><wfw:comment>http://blogs.msdn.com/bethmassi/rsscomments.aspx?PostID=9536792</wfw:comment><description>&lt;P&gt;Yesterday &lt;A href="http://www.intellectualhedonism.com/" target=_blank mce_href="http://www.intellectualhedonism.com/"&gt;Carl&lt;/A&gt; posted another &lt;A href="http://www.dnrtv.com/default.aspx?showNum=137" target=_blank mce_href="http://www.dnrtv.com/default.aspx?showNum=137"&gt;dnrTV show with yours truly&lt;/A&gt;. This time I’m talking about the &lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c6e744e5-36e9-45f5-8d8c-331df206e0d0&amp;amp;DisplayLang=en" target=_blank mce_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;, something that I’ve &lt;A href="http://blogs.msdn.com/bethmassi/archive/tags/XML/Office/default.aspx" target=_blank mce_href="http://blogs.msdn.com/bethmassi/archive/tags/XML/Office/default.aspx"&gt;written and spoken about many times&lt;/A&gt;. &lt;A href="http://www.dnrtv.com/default.aspx?showNum=137" target=_blank mce_href="http://www.dnrtv.com/default.aspx?showNum=137"&gt;In this episode&lt;/A&gt; I show how to use Word 2007 content controls and map them to custom XML parts so that you can query structured data from unstructured documents using Visual Basic’s LINQ to XML. What’s really cool about the Open XML format is that you don’t need Office installed at all – no COM Interop needed. You’re working with the file formats directly. And it’s super simple using VB’s XML literals and LINQ with the SDK.&lt;/P&gt;
&lt;P&gt;Unfortunately I didn’t have a lot of time when I did the show with Carl and I couldn’t finish my demos. So this morning I filmed another quick episode that shows how to create documents from database data directly, so keep on the lookout for the follow up show :-).&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.dnrtv.com/default.aspx?showNum=137" target=_blank mce_href="http://www.dnrtv.com/default.aspx?showNum=137"&gt;&lt;STRONG&gt;dnrTV Show: Beth Massi on the Open XML SDK&lt;/STRONG&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;And here are the links from the show:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c6e744e5-36e9-45f5-8d8c-331df206e0d0&amp;amp;DisplayLang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c6e744e5-36e9-45f5-8d8c-331df206e0d0&amp;amp;DisplayLang=en"&gt;Open XML Format SDK 2.0&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyId=46B6BF86-E35D-4870-B214-4D7B72B02BF9&amp;amp;displaylang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyId=46B6BF86-E35D-4870-B214-4D7B72B02BF9&amp;amp;displaylang=en"&gt;Microsoft Visual Studio Tools for the Office System Power Tools v1.0.0.0&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://www.codeplex.com/dbe" mce_href="http://www.codeplex.com/dbe"&gt;Word 2007 Content Control Toolkit &lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.com/vsto" mce_href="http://msdn.com/vsto"&gt;VSTO Developer Center&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;[UPDATE: Here's code samples (also includes a presentation pptx)]&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A class="" id=ctl00_ctl00_WideContent_ProjectTitleControl1_ProjectTitleLink href="http://code.msdn.microsoft.com/openxmlvb" target=_blank s_oid="http://code.msdn.microsoft.com/openxmlvb" s_oidt="0" mce_href="http://code.msdn.microsoft.com/openxmlvb"&gt;&lt;SPAN id=ctl00_ctl00_WideContent_ProjectTitleControl1_TitleLabel&gt;&lt;FONT color=#3e62a6&gt;Working with Open XML in Visual Basic&lt;/FONT&gt;&lt;/SPAN&gt;&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=9536792" 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/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/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/VSTO/default.aspx">VSTO</category></item></channel></rss>