“How Do I” Videos for Visual Studio 2010
09 February 10 09:52 AM

If you haven’t seen these yet, various members of the languages team have released some How Do I videos on Visual Studio 2010 including new language features in Visual Basic 10 and C# 4.

  1. How Do I: Use Autoimplemented Properties in Visual Basic?
  2. How Do I: Use Implicit Line Continuation in Visual Basic 10?
  3. How Do I: Use Highlight References in the Visual Studio 2010 IDE?
  4. How Do I: Use Code Snippets in the Visual Studio 2010 IDE?
  5. How Do I: Use Generate from Usage in Visual Studio 2010?
  6. How Do I: Enhance Performance in the Visual Studio 2010 IDE when Editing VB Code?
  7. How Do I: Step with The Debugger in Visual Studio 2010?
  8. How Do I: Use Named and Optional Parameters in C# 4.0?
  9. How Do I: Use COM Interop and Office in C# 4.0?

Also make sure to check out the VS 2010 code samples and walkthroughs.

Enjoy!

Postedby Beth Massi | 0 Comments    
Updated Samples for Visual Studio 2010 Release Candidate
08 February 10 05:16 PM

If you haven’t heard, Jason Zander announced today that the Release Candidate (RC) for Visual Studio 2010 is now available for MSDN Subscribers here. The RC will be made available to the public on Wednesday the 10th.

We also just refreshed all the WPF & Silverlight Data binding, VSTO and SharePoint Dev samples on Code Gallery to match the RC bits so check them out once you’ve downloaded and installed the RC:

Here’s some more additional resources to look through:

Office Development with VS:

SharePoint Development with VS:

WPF & Silverlight Data Apps:

Enjoy!

SQL Server 2008 Express How Do I videos
04 February 10 06:45 PM

Recently I’ve gotten a lot of questions about how to work with and connect to SQL Express data. (SQL Express edition is the free version of SQL Server that comes with Visual Studio). Well if you haven’t seen these videos on getting started with SQL Express you should check them out:

SQL Server 2008 Express How-To-Guide Series

I recommend this one in particular, SQL Server Express Troubleshooting which shows how to add logins to SQL server and troubleshoot connectivity problems.

Enjoy!

Postedby Beth Massi | 2 Comments    
Filed under: , ,
Community Article: Certificate Expiration in ClickOnce Deployment
02 February 10 11:01 AM

We just published another community article onto the Visual Basic and VSTO Developer Centers by Robin Shahan (Client App Dev MVP) on how to handle certificate expiration on ClickOnce deployments. She explains in her own entertaining way how to handle a variety of cases depending on the version of the .NET framework and what OS is installed. She even has a flowchart to help you navigate all the options… here’s a teaser:image 

 

Sample source code is included here which includes a PDF version of the full flowchart.

Read the article Certificate Expiration in ClickOnce Deployment.

Enjoy!

Postedby Beth Massi | 3 Comments    
New Learning Resources on the Visual Basic Developer Center
01 February 10 11:33 AM

A couple months ago we revamped the Learn pages on the VSTO Developer Center with more content that allows you to pivot on more fine-grained topics and tasks under each type of Office solution. And as a result, we’ve had a lot more people finding the content they need.

Today we’ve started doing the same type of organization on the Visual Basic Developer Center Learn pages. We’ve started with the Introductory Topics and Language Syntax pages. To get there, head to http://msdn.com/vbasic and then click the Learn tab. There you will see a set of general topic areas to explore.

image 

If you select Introductory Topics or Language Syntax you will be taken to a new set of pages that lets you browse on more topics and tasks. Select a topic from the list on the left and the content will change on the right. I’ve collected a good set of content from a variety of sources like the MSDN library, blogs, How Do I videos, and other learning sites. Hopefully this organization makes it easier for you to find what you need related to language syntax whether that be a video, article, blog, webcast, etc.

image

However, if you still like to see, say, all the videos or articles related to VB Language, you can select the icons on the right-rail. I’ll be working on this type of structure for the rest of these pages and will release them as I finish each one. It takes a while to categorize all the content I want so I rather release section by section. Next section I’m working on will be Data Access.

Am I missing a topic or some good content you want to see? Please send me feedback by making a comment to this post or send me an email.

Happy Learning!

Postedby Beth Massi | 2 Comments    
Filed under:
Creating a SharePoint Visual Web Part using Visual Studio 2010
28 January 10 07:27 PM

Last year we built a business application for order management for Northwind Traders on the Office and SharePoint platform using Visual Studio 2008 and Office & SharePoint 2007. Lately I’ve been writing articles that show how to upgrade it to Office & SharePoint 2010 using Visual Studio 2010. If you missed them:

I also released the migrated sample application here: http://code.msdn.microsoft.com/OBANorthwind

If you look at the VS2010 solution in that sample you’ll see a few extra projects in there that add more functionality to our application. One of those new pieces is a Visual Web Part that shows low inventory from the Northwind database. Northwind’s operations department not only wants to see Order status in SharePoint (which we built into our workflow) but also wants to be able to quickly eyeball any low inventory. Visual Studio 2010 includes many new project and item templates for SharePoint 2010, one being a Visual Web part. If you’re familiar with ASP.NET development then you can easily start building a SharePoint web part using Visual Studio 2010. Let’s see how we can do that.

Creating a Visual Web Part Project in Visual Studio

First thing you need to do is open Visual Studio as an Administrator. You need to do this when you are programming against SharePoint because the debugger & tools need Administrator access to SharePoint. Visual Studio will warn you if you forget.

Next create a new project and select SharePoint 2010 -> Visual Web Part. (Make sure you select Visual Web Part and not Web Part). Name the project LowInventoryWebPart. The SharePoint Customization Wizard opens. Select your SharePoint site, in my case I’ve created a team site called Northwind.

Notice that “Deploy as a farm solution” is the only option. This means that when you design a visual web part it is available to all site collections on the farm as opposed to a sandboxed solution which is only available at the site collection level. The key difference between these two is what processes they run in, farm being the IIS worker process, which dictates which access levels they have. For more information on the differences see Differences Between Sandboxed and Farm Solutions in the MSDN library.

image

Click Finish and the the ASP.NET designer opens and displays a web user control that we can design. But first we need to add a service reference to our data service. If you recall we are exposing our line-of-business data (in this case the Northwind SQL database) over WCF-REST using a data service. As long as we can access this service from our SharePoint instance once we deploy, then we’re good to go.

To add a Service Reference to the data service, select Project -> Add Service Reference. If your data service is in the same solution as in the case of this one, just click Discover to browse the types that the data service exposes. Set the Namespace to NorthwindService and click OK.

Designing the Visual Web Part and Loading Data

I don’t have any super-fancy design skillz here so we’re just going to create a data-bound GridView and then write a LINQ query to get the low inventory items to display. The key takeaway is that this would be the same code to write if we were writing any ASP.NET webpage, you can even use the Ajax controls in the toolbox. In the next section below we’ll take advantage of the SharePoint server model in order to interact with SharePoint lists, but to pull data from our LOB database it’s standard data access stuff.

So from the Data tab in the toolbox, I’m going to drag a GridView onto the form. I’m also going to drop a Label at the bottom of the form to display any errors or messages. I can style these controls how I like and these styles will be displayed the same way in the Web Part in SharePoint.

image

Right-click on the designer to open the code-behind. In the Page_Load event handler we’ll write the code to load the low inventory from our data service:

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports LowInventoryWebPart.NorthwindService

Partial Public Class LowInventoryWebPartUserControl
    Inherits UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        'Webpart Code to display Low Inventory:
        Try
            Dim ctx As New NorthwindEntities(New Uri("http://myserver/Northwind.svc/"))

            Dim result = From p In ctx.Products _
                         Where p.UnitsInStock <= p.ReorderLevel _
                         Order By p.UnitsInStock


            Me.GridView1.AutoGenerateColumns = True
            Me.GridView1.DataSource = result.ToList()
            Me.GridView1.DataBind()

        Catch ex As Exception
            Me.Label1.Text = ex.ToString
        End Try
    End Sub

End Class

Debugging the Web Part

Let’s test this so far. Set the LowInventoryWebPart project as the startup project of your solution (if it isn’t already) and set a breakpoint on the LINQ query. Hit F5 and Visual Studio will recycle the IIS worker process, package & deploy & activate the feature, and attach the debugger automatically for you. This is shown in the Output window and it’s fun to watch so you may want to pin that window open. :-)

------ Deploy started: Project: LowInventoryWebPart, Configuration: Debug Any CPU ------

Active Deployment Configuration: Default
Run Pre-Deployment Command:
  Skipping deployment step because a pre-deployment command is not specified.
Recycle IIS Application Pool:
  Skipping application pool recycle because no matching package on the server was found.
Retract Solution:
  Skipping package retraction because no matching package on the server was found.
Add Solution:
  Adding solution 'LowInventoryWebPart.wsp'...
  Deploying solution 'LowInventoryWebPart.wsp'...
Activate Features:
  Activating feature 'Feature1' ...
Run Post-Deployment Command:
  Skipping deployment step because a post-deployment command is not specified.
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========

The nice thing is that Visual Studio handles all the deployment as well as all the cleanup. When you close the debugger the feature is deactivated and the package is retracted and deleted. Notice that you can also specify pre and post deployment commands, plus a whole lot more. The Feature and Package designers are very flexible. (For more information watch this Channel 9 Interview: SharePoint Feature and Package Designers in Visual Studio 2010 and read Packaging and Deploying SharePoint Solutions in the MSDN library.)

In order to debug this sucker we first have to add it to a page on our site. When the debugger starts up, it opens a page to the site we specified in the SharePoint Customization Wizard in the beginning. So select Site Actions in the upper left, then Edit Page. Select the Insert tab on the Ribbon and click Web Part. Select the Custom category and you should see your web part. Select it and click Add on the bottom right of the section.

image

At this point you should hit your breakpoint. Hit F11 and the query will return the low inventory so you can see the data as you design the page. The Page_Load will get called a couple times when designing the web part so keep that in mind.

Next drop down the LowInventoryWebPart menu at the top right of the web part and select Edit Web Part to open the properties. Set the Title to “Low Inventory” and click OK. On the Page tab on the Ribbon select Save to save and close the page editor. Now we’ve got a nice looking web part for browsing low inventory. Sweet!

image

Close the browser window and this will close your debugging session, recycle the IIS app pool, deactivate the feature and retract the solution automatically for you. These steps are also displayed in the Output window.

Interacting with SharePoint using the Server Object Model

Well that was pretty easy to incorporate our LOB data into SharePoint with a simple web part and a data service but what if the user sees a critically low item and wants to add an item to the Task list? It would be nice if they could do it right here. The way we interact with SharePoint in a Visual Web Part is via the SharePoint Server Object Model. There are also SharePoint client object models as well; one for Silverlight clients and one for other .NET Framework clients. But because we are on the server when we are running a web part, we have access here to the server object model.

So let’s add a TextBox and a Button to our web part that allow the user to enter tasks directly onto the Task list. Go back to design mode on the Web Part, hit enter under the GridView and and type “Create Task:” under it. From the Standard tab on the toolbox, drag a Textbox onto the form then drag a Button and set its Text property to “Add”.

Double-click on the button and we can write this code in the Button1 click event handler to add a Task:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
    'Webpart code to Add to task list 
    Try
        Dim mySite As SPWeb = SPContext.Current.Web
        Dim listItems As SPListItemCollection = mySite.Lists("Tasks").Items

        Dim item As SPListItem = listItems.Add()

        item("Title") = Me.TextBox1.Text
        item("Assigned To") = mySite.AllUsers(Me.Context.User.Identity.Name)

        item.Update()
        Me.TextBox1.Text = ""
        Me.Label1.Text = "Your task has been added to the task list"

    Catch ex As Exception
        Me.Label1.Text = ex.ToString
    End Try
End Sub

The way we access the current SharePoint site by using the SPContext object and getting the Current.Web. Just like you have an HttpContext in ASP.NET development you have a SPContext in SharePoint development. So let’s test this one out. Put a breakpoint on the Button1_Click handler and hit F5 to deploy and debug. The second time around you don’t need to add the web part to the site page again but it will be refreshed with our new controls and code.

Now create a task by entering a description and click the Add button. The breakpoint will hit and you can debug the code and explore some of the server object model.

image

When you’re done, navigate to the task list to see that your task has been added.

image

This project is included in the Northwind OBA solution for VS2010 located here http://code.msdn.microsoft.com/OBANorthwind  so have a look. If you’re an ASP.NET developer just getting started with SharePoint development there’s still a lot to learn, but fortunately Visual Studio 2010 can help make an unfamiliar platform easier to approach with the right tools in hand.

Download Visual Studio 2010 Beta and read the walkthroughs here: http://msdn.com/vstudio

Enjoy!

New Blog from the WPF & Silverlight Designer Team Just Launched!
22 January 10 02:12 PM

The WPF and Silverlight Designer team (a.k.a Cider team) launched a blog last week and they already have a TON of content!
http://blogs.msdn.com/wpfsldesigner/

Wow I need to catch up!  I’m told during the months of January and February they will be adding a good bit of WPF & Silverlight content that will focus on the Designer toolset and walkthroughs using the Designer as well as some posts for control authors.

You can leave feedback for the Cider Team on the blog or you can send comments and questions using Twitter and include #wpfdesigner or #sldesigner in your tweets.

My favorite tag on the blog so far is How To. ;-)

Enjoy! (I know I will)

Postedby Beth Massi | 5 Comments    
Northwind Office Business Application Updated for Visual Studio, Office & SharePoint 2010
19 January 10 08:21 PM

Last year we built a business application for order management for Northwind Traders on the Office and SharePoint platform using Visual Studio 2008 and Office & SharePoint 2007. Recently I started releasing articles that show how to upgrade the VS2008 version to VS2010:

Today I updated the sample with some more goodies including some SharePoint 2010 web parts that I’ll write about soon. But I wanted to let you know sooner rather than later that you can play with all of the code today. This is also the same code I demonstrated last week at our East Bay.NET User’s group meeting.

Here ya go: http://code.msdn.microsoft.com/OBANorthwind

This sample was built using Visual Studio 2010 Beta 2, Office 2010 Beta & SharePoint 2010 Beta and it demonstrates:

  1. A way to easily expose line-of-business (LOB) data using WCF Data Services (formerly known as ADO.NET Data Services)
  2. An Outlook 2010 Add-in that displays LOB data in a WPF control that I built in 5 minutes using the new drag-drop data binding and designer features
  3. How to store and retrieve structured data from Word 2010 documents
  4. An Excel 2010 document customization that edits LOB data through the data service and provides data visualization
  5. A SharePoint 2010 Document Library Workflow that adds Order info to the database by reading word documents and updates and reports order statuses based on changes in the database using the data service
  6. A SharePoint 2010 Visual Web Part that reports low inventory in the database using the data service and allows users to add tasks
  7. A SharePoint 2010 Silverlight Web Part that demonstrates how to deploy Silverlight web parts to SharePoint 2010 and use the SharePoint Silverlight client library to add tasks

Enjoy!

Migrating a 2007 Workflow to Visual Studio & SharePoint 2010
15 January 10 04:42 PM

Lately I’ve been converting an Office business application we built last year with Visual Studio 2008 to Visual Studio and Office 2010. Last couple posts we tackled converting the Outlook client piece. In this post I want to focus on the server side and show how we can convert the SharePoint 2007 workflow we built with Visual Studio 2008 to a SharePoint 2010 workflow in Visual Studio 2010.

In Visual Studio 2008 under the Office –> 2007 node in the New Project dialog we could choose from a variety of Office client templates. There was included a SharePoint Sequential Workflow and SharePoint State Machine Workflow. These were the only SharePoint templates available to us. As you’ve probably heard already, Visual Studio 2010 provides much more support for SharePoint and includes many more project and item templates, now included in its own SharePoint –> 2010 node:

image

You can still build Sequential and State Machine workflows for SharePoint 2007 in Visual Studio 2010 but you’ll be able to do a lot more against SharePoint 2010. Let’s see how we can convert the Sequential Workflow we built against SharePoint 2007 to SharePoint 2010 using Visual Studio 2010.

Convert the Solution to Visual Studio 2010

The first step is to open the VS2008 solution in VS2010. This will through the (probably familiar) Visual Studio conversion wizard. This doesn’t change the code itself, it just upgrades the solution and project files. Now if you are doing this on a machine that doesn’t have SharePoint 2007 installed, but instead has SharePoint 2010, then you won’t be able to run this workflow. Makes sense. You need to have the version of SharePoint you’re developing against on the dev box. Luckily, with SharePoint 2010 you can have it installed on a client OS like Win 7.

Create the Order Document Library on SharePoint 2010

Since we want to migrate this example to SharePoint 2010, I have to have that installed that on my development machine (which also means we can’t run the 2007 workflow). We also need to set up SharePoint with the same document library we had before or our migrated code won’t run either.

If you recall this workflow processes purchase orders that are added to the Orders document library so we’ll also need to set that up with the same columns we had before. Even though the UI looks a bit different, the process is the same as I described in the previous article on SharePoint 2007. Once you get the Order document library set up with the additional columns we need, it should look similar to this:

image

Add a New SharePoint 2010 Sequential Workflow

Since we can’t run the SharePoint 2007 workflow, the easiest thing to do is add a new SharePoint 2010 Workflow project to your solution and then move the workflow code over. With your solution open, select File –> Add –> New Project, expand the SharePoint 2010 node and then select the SharePoint 2010 Sequential Workflow.

imageThe SharePoint Customization wizard opens. I’ll name this project NorthwindWorkflow2010 and then I need to select my SharePoint 2010 site, set the display name and select List Workflow. (Notice in SharePoint 2010 we can also create a Site Workflow as well).

Click Next and then select the same lists to associate the workflow with that you were using before in the 2007 Workflow. In the case of this example the only thing to select is the Orders document library in the first dropdown.

Click Next and then select how the workflow should start up. In our case leave the defaults. We want this workflow to start up when an item is added to the list.

Once you hit Finish the project is generated and appears in the Solution Explorer.

Add Service and Assembly References, then Copy your Code

image Next you’ll need to re-add any assembly references you were using before to get your workflow code running. In this example we need to add a reference to the DocumentFormat.OpenXml. I also need to add a service reference to the data service we were using to access our LOB data, in this case NorthwindDataService. In fact, I have this already in the Solution so I can just right-click on the NorthwindWorkflow2010 project, select Add Service Reference, and then in the dialog just click the Discover button to find the data service. Name it NorthwindServiceReference and click OK.

Now comes the fun part. We can just copy all the code files into the new project. First though I need to rename the Workflow1 “sub-folder” to ProcesOrder in the 2010 project. Yes you should notice that the file structure is different in the 2010 project. For instance, you’ll see Package and Features “folders” under the project. This is because there are new tools for packaging features (like Lily showed us on Channel 9) among a ton of other tools. We refer to these “folders” as SharePoint Project Items (SPI).

image Once you rename the Workflow SPI to ProcessOrder then you can delete the actual workflow Workflow1. Then drag the ProcessOrder workflow from the old project into this new one, just make sure you add it to the ProccessOrder SPI. Also drag all the other code files into your new project.

Next open up the Elements.xml file and make sure you see the correct name of your workflow in there. Make sure the CodeBesideClass attribute is correct:

CodeBesideClass="NorthwindWorkflow2010.ProcessOrder"

If this isn’t correct then your workflow will deploy correctly, but it will fail to start so be sure to double-check this.

The only other thing we need to do now is fix up one Imports statement in our code-behind for the workflow because the name of our project changed. In our example, the OrderManager.vb is referencing our service so that needs to be fixed up:

Imports NorthwindWorkflow2010.NorthwindServiceReference

Finally remove the old workflow project (NorthwindWorkflow) from the solution by right-clicking on the project name and selecting remove.

Run it!

Now you should be able to run the new workflow in SharePoint 2010. Set the NorthwindWorkflow2010 as your startup project, make sure you start the NorthwindDataService and then hit F5 to deploy and debug. When we add a new purchase order to the Orders doc library the workflow will run and process our order by putting the order data into the database using the data service just like before, but now we’re developing against SharePoint 2010 and we can take advantage of the new tools in Visual Studio 2010.

If you’d like to play with this workflow (plus all the other pieces of the Northwind Traders application) you can download the entire solution upgraded to Visual Studio, Office and SharePoint 2010 here.

Next time I’ll show how we can create a simple Visual Web Part that displays inventory information from the Northwind database and allows us to assign tasks using the SharePoint server object model.

Enjoy!

Visual Studio 2010 “Tip of the Day” Returns!
13 January 10 11:27 AM

If you used to rely on Sara Ford and her amazing Visual Studio tips you’ll be happy to know that there’s a new tipster in town taking over for her for Visual Studio 2010. Zain Naboulsi, a Developer Evangelist, has started the Tip of the Day series back up again!

Check it out: http://blogs.msdn.com/zainnab/archive/tags/vs2010/Tips+and+Tricks/default.aspx

Enjoy!

Postedby Beth Massi | 1 Comments    
Filed under: , ,
Speaking at East Bay.NET Tomorrow Night on VSTO & SharePoint 2010
12 January 10 11:37 AM

Wow, welcome back from the holidays! I hope yours were as fun and relaxing as mine were. It's always a wonderful time of year to stay with friends and family and concentrate on what's really important in life.

Well it's time to get back at it and I am refreshed and ready to go! I'm working on a fun-filled presentation for EastBay.NET on building business applications on the Office and SharePoint 2010 platform using Visual Studio 2010. Here's the official talk description:

Building Business Productivity Solutions with Visual Studio 2010 
The Visual Studio and Office teams have made significant investments in improving the developer experience for building and deploying Office and SharePoint applications. In this demo-heavy session, we will walk through an end-to-end business application built on Office and SharePoint 2010 and discuss architecture options to consider when building these systems. You'll learn how to use Visual Studio and it’s enhanced set of RAD tools that allows users to consume external line-of-business data within the familiar Office UIs.

When: Wednesday, 1/13/2010 at 6:45 PM
Where: University of Phoenix Learning Center in Livermore, 2481 Constitution Drive, Room 105

Register for this meeting here.

I'm also playing with some Silverlight right now to see if I can squeeze in how to deploy Silverlight web parts to SharePoint 2010. The deployment is made so easy with Visual Studio 2010. (Check out Mike's Channel 9 interview on how to do it: Implementing a Silverlight SharePoint WebPart with Visual Studio 2010)

And as an added bonus I talked Ward Bell from IdeaBlade (Silverlight MVP) into coming out and presenting FUNdamentals, a 30 minute intro session we do before our main talks here at EastBay.NET. He's going to show you the basics of WCF Data Services (a.k.a ADO.NET Data Services, a.k.a Astoria). I'll be using this technology to expose our LOB data to Office and SharePoint but I won't have time to show you more than a brief overview on how to set it up. So if you've never used the technology then come early and learn from Ward how it works.

It should be a very fun filled evening from two awesome speakers (if I do say so myself ;-)) so I hope to see you there.

Enjoy!

Build WPF Data Controls for Outlook Addins Easily with VS2010
21 December 09 02:14 PM

Last post I showed how to migrate our Northwind Outlook client to .NET 4 and Office 2010. 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 originally built this with Visual Studio 2008, 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.

Today I want to show how we can use drag & drop data binding and the new WPF designer in Visual Studio 2010 to quickly create this control without writing one line of XAML ourselves.

Displaying WPF Controls in Form Regions with ElementHost

Office clients by default work with Windows Forms controls. If you create a new Form Region 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 ElementHost control 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.

image

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.

Using the Data Sources Window with WPF

Let’s create a new WPF control called OrderHistoryDD where we’ll use drag & drop data binding from the data sources window. Project –> Add New Item, then select User Control (WPF). To view the data sources window select menu Data –> Show Data Sources. Because we already have added a service reference to our data service (which we built in part 1), you will see the client types that were generated for us appear in the data sources window.

image

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.

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.

However, we are only displaying data to the user here (new orders are handled as POs in Word and the editing is done by our shipping department in the Excel client) 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].

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.

Since we are not allowing edits, in the Property window for the DataGrid, set the IsReadOnly property to True. Also set the ColumnWidth property to Auto. 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.

image

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.

Now we need to display the related Order Details. To do this, back in the data sources window expand the Order Details under the Orders. 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.

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.

image

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.

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

image

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.

Styling the DataGrids and Sharing Style Resources

image

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 Brush Editor. 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.

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 Extract Value to Resource. Name the resource and then click OK to add it to the resources section of the user control.

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.

Hooking Up the Data to CollectionViewSource

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.

We already have written the the code to load the data into a List(Of Orders). The same code we wrote for our VS2008 version here 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. I’ve talked about CollectionViewSources for master-details before. You can see this in the XAML that was generated for us, as well as the related OrdersOrder_DetailsViewSource:

<UserControl.Resources>
    <CollectionViewSource x:Key="OrdersViewSource" 
d:DesignSource="{d:DesignInstance my:Order, CreateList=True}" /> <CollectionViewSource x:Key="OrdersOrder_DetailsViewSource"
Source="{Binding Path=Order_Details,
Source={StaticResource OrdersViewSource}}" />

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:

Imports System.Windows.Data
Public Class OrderHistoryDD Public ReadOnly Property OrdersViewSource As CollectionViewSource Get Return CType(Me.Resources("OrdersViewSource"), CollectionViewSource) End Get End Property
End Class

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:

'Load the data from the service
Dim ordersList As New List(Of Order)(customerOrders)
'Set this ordersList as the DataContext of our WPF user control:
'Me.OrderHistory1.DataContext = ordersList

'In VS2010 CollectionViewSources are used instead:
Me.OrderHistoryDD1.OrdersViewSource.Source = ordersList

Now rebuild and run it to see your lovely new user control appear in Outlook:

image

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.

Writing a Converter to Aggregate Totals

I’ve talked about how to write a converter to format data in controls exactly how you like. 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.

Imports System.Windows.Data
Imports NorthwindOutlookClient.NorthwindService.NorthwindModel

'Used by the OrderHistory WPF control to display line totals and Order total in the UI
Public Class OrderTotalConverter
    Implements IValueConverter

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type,
                            ByVal parameter As Object,
                            ByVal culture As System.Globalization.CultureInfo) As Object _
                        Implements System.Windows.Data.IValueConverter.Convert

        Dim total As Double = 0.0
        If TypeOf value Is Order_Detail Then
            'return the line item total
            Dim o = CType(value, Order_Detail)
            total += o.Quantity * o.UnitPrice

        ElseIf TypeOf value Is IEnumerable(Of Order_Detail) Then
            'return the order total
            For Each o As Order_Detail In value
                total += o.Quantity * o.UnitPrice
            Next
        End If
        Return total
    End Function

    Public Function ConvertBack(ByVal value As Object,
                                ByVal targetType As System.Type,
                                ByVal parameter As Object,
                                ByVal culture As System.Globalization.CultureInfo) As Object _
                            Implements System.Windows.Data.IValueConverter.ConvertBack
        Return Nothing
    End Function
End Class

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.

image

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.

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.

image

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 source code which works with Visual Studio 2010 Beta 2 and Outlook 2010 Beta onto Code Gallery so have a look.

Enjoy!

Postedby Beth Massi | 6 Comments    
Migrating an Outlook Client to .NET Framework 4 in Visual Studio 2010
15 December 09 11:12 PM

Early this year we built a business application for order management for Northwind Traders on the Office and SharePoint platform using Visual Studio 2008 and Office & SharePoint 2007. If you missed them:

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 (built in part 1) and is displayed in the reading pane in Outlook for each customer.

Today I want to take a look at how we can migrate the Outlook client we built in part 2 to Office 2010 and .NET Framework 4.0 Client Profile 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. 

I set up a Windows 7 VHD with Visual Studio, SharePoint & Office Betas that I’ll be using for development, just like I explained in this post - Setting up Windows 7 for Office & SharePoint 2010 Beta Development. If you’d like to follow along you can download the Visual Studio 2008 version of the code here.

Required Changes for the New VSTO 4 Runtime

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 Visual Studio 2010 resources page on the VSTO Dev Center are valuable but if you are migrating you should pay close attention to this item -

Migrating Office Solutions to the .NET Framework 4

I also recommend familiarizing yourself with the new VSTO4 Runtime here -

Visual Studio Tools for Office Runtime Overview

In particular, if your Outlook project uses Form Regions or the Ribbon designer then you will have some work to do if you target .NET Framework 4 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).

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 Northwind Outlook client.

Migrating the Outlook Solution to Visual Studio 2010

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.

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 How to Upgrade Office Solutions and Configuring a Computer to Develop Office Solutions).

Since my development environment 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.” However it will build and run just fine in Outlook 2010.

image

Updating the Target Framework to .NET 4

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.

image

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.  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 new Windows, WPF and Office projects.

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.

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.

Update Outlook Projects that Contain Form Regions

Since we’ll be modifying the designer generated code you’ll need to make sure you click the Show All Files toolbar button on the Solution Explorer. Now we can open up the EmailForm.Designer.vb file in the editor.

This documentation contains the step-by-step code conversions that you need to perform to upgrade your form regions. First we need to modify the declaration of the form region class so that it derives from FormRegionBase instead of FormRegionControl:

<System.ComponentModel.ToolboxItemAttribute(False)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class EmailForm
    Inherits Microsoft.Office.Tools.Outlook.FormRegionBase

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:

    Public Sub New(ByVal formRegion As Microsoft.Office.Interop.Outlook.FormRegion)
        MyBase.New(formRegion)
        Me.InitializeComponent()
    End Sub

However in .NET 4 we need to change this to:

    Public Sub New(ByVal formRegion As Microsoft.Office.Interop.Outlook.FormRegion)
        MyBase.New(Globals.Factory, formRegion)
        Me.InitializeComponent()
    End Sub

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)

Private Shared Sub InitializeManifest(
ByVal manifest As Microsoft.Office.Tools.Outlook.FormRegionManifest, ByVal factory As Microsoft.Office.Tools.Outlook.Factory)

A Better Way to Upgrade (for now) – Working Around a Bug in Visual Studio 2010 Beta 2

Steps 5-8 of the documentation 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.

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.

First clean the solution to remove the registered Add-In. From the menu select Build –> Clean NorthwindOutlookClient.

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.

Next go to the main menu and select File –> Add –> New Project then make sure you select .NET Framework 4 and then choose Outlook 2010 Add-in and name it NorthwindOutlookClient.

image

Next right-click on the project and select Set as StartUp Project. Then Add –> Existing Item and select all the code, app.config, .xaml and .gif files in the NorthwindOutlookClient_OLD directory:

image

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

Next we need to re-add our Service Reference to our data service by right clicking and select Add –> Service Reference, click Discover button and then name the service the same thing, NorthwindService.

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.

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.

Back to Migrating the Form Region

Now you can get back to upgrading your Form Region as explained in steps 5-8 . Add a new Form Region by selecting Project –> 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):

image

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):

Partial Public Class EmailFormFactory
    Implements Microsoft.Office.Tools.Outlook.IFormRegionFactory

    Public Event FormRegionInitializing As  _
        Microsoft.Office.Tools.Outlook.FormRegionInitializingEventHandler

    Private _Manifest As Microsoft.Office.Tools.Outlook.FormRegionManifest

    <System.Diagnostics.DebuggerNonUserCodeAttribute()> _
    Public Sub New()
        Me._Manifest = Globals.Factory.CreateFormRegionManifest()
        EmailForm.InitializeManifest(Me._Manifest, Globals.Factory)
    End Sub

    <System.Diagnostics.DebuggerNonUserCodeAttribute()> _
    ReadOnly Property Manifest() As Microsoft.Office.Tools.Outlook.FormRegionManifest _
             Implements Microsoft.Office.Tools.Outlook.IFormRegionFactory.Manifest
        Get
            Return Me._Manifest
        End Get
    End Property

    <System.Diagnostics.DebuggerNonUserCodeAttribute()> _
   Function CreateFormRegion(ByVal formRegion As Microsoft.Office.Interop.Outlook.FormRegion) As _
             Microsoft.Office.Tools.Outlook.IFormRegion _
             Implements Microsoft.Office.Tools.Outlook.IFormRegionFactory.CreateFormRegion
        Dim form As EmailForm = New EmailForm(formRegion)
        form.Factory = Me
        Return form
    End Function

    <System.Diagnostics.DebuggerNonUserCodeAttribute()> _
    Function GetFormRegionStorage(ByVal outlookItem As Object,
                  ByVal formRegionMode As Microsoft.Office.Interop.Outlook.OlFormRegionMode,
                  ByVal formRegionSize As Microsoft.Office.Interop.Outlook.OlFormRegionSize) _
As Byte() _
Implements Microsoft.Office.Tools.Outlook.IFormRegionFactory.GetFormRegionStorage Throw New System.NotSupportedException() End Function <System.Diagnostics.DebuggerNonUserCodeAttribute()> _ Function IsDisplayedForItem(ByVal outlookItem As Object, ByVal formRegionMode As Microsoft.Office.Interop.Outlook.OlFormRegionMode, ByVal formRegionSize As Microsoft.Office.Interop.Outlook.OlFormRegionSize) _ As Boolean _
Implements
Microsoft.Office.Tools.Outlook.IFormRegionFactory.IsDisplayedForItem Dim cancelArgs As Microsoft.Office.Tools.Outlook.FormRegionInitializingEventArgs = Globals.Factory.CreateFormRegionInitializingEventArgs(outlookItem, formRegionMode, formRegionSize, False) cancelArgs.Cancel = False RaiseEvent FormRegionInitializing(Me, cancelArgs) Return Not cancelArgs.Cancel End Function <System.Diagnostics.DebuggerNonUserCodeAttribute()> _ ReadOnly Property Kind() As Microsoft.Office.Tools.Outlook.FormRegionKindConstants _ Implements Microsoft.Office.Tools.Outlook.IFormRegionFactory.Kind Get Return Microsoft.Office.Tools.Outlook.FormRegionKindConstants.WindowsForms End Get End Property End Class End Class Partial Class WindowFormRegionCollection Friend ReadOnly Property EmailForm() As EmailForm Get For Each Item As Object In Me If (TypeOf (Item) Is EmailForm) Then Return CType(Item, NorthwindOutlookClient.EmailForm) End If Next Return Nothing End Get End Property End Class

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.

Removing the SecurityTransparent Attribute

The next section of the documentation on upgrading Office solutions has information on how to Remove the SecurityTransparent attribute from Office Projects that you upgrade from Visual Studio 2008. 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.

Run it!

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.

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, take a look at the documentation for details. Hopefully dealing with a little migration pain now will pay off in the long run to you and your users.

Resources

For more information on building Office solutions with Visual Studio please check out:

For more information on underscores in Visual Basic 10 in Visual Studio 2010 see:

Enjoy!

Postedby Beth Massi | 2 Comments    
Office Development with Visual Studio Tutorial Series – Part 2
08 December 09 10:51 AM

Last month Robert Green, 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!

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 VSTO Developer Center:

Building an Office Business Application Part 2 – Generating Automobile Quotes

And if you missed part 1:

Building an Office Business Application Part 1 - Scheduling Customer Appointments

If you’re just getting started with Office development in Visual Studio, this is a great place to start.

Enjoy!

Postedby Beth Massi | 1 Comments    
Setting up Windows 7 for Office & SharePoint 2010 Beta Development
02 December 09 07:16 PM

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. As always, your mileage may vary.

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, Setting Up the Development Environment for SharePoint Server , SharePoint Deployment, Determine hardware and software requirements and SharePoint 2010 Beta Release Known Issues.

OS Requirements & Boot From VHD

Before you attempt to set up a Windows 7 development environment, I highly 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 I used these instructions to create a Win7 64-bit VHD 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.

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.

What to Install - SharePoint Foundation or SharePoint Server?

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. :-)

Download Microsoft SharePoint Foundation 2010 Beta here.

Download Microsoft SharePoint Server 2010 Beta here.

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


Installing SharePoint 2010 Beta on Windows 7


Read these instructions carefully: Setting Up the Development Environment for SharePoint Server. 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.

Step 2: Install the Prerequisites for SharePoint 2010

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.

Next reboot.

BEFORE going to Step 3, you will need to install a WCF hotfix as described in this post which fixes an "Unrecognized attribute 'allowInsecureTransport'" error. The WCF hotfix for Windows 7 is available here. After installing this hotfix, reboot.

Now you’re at Step 3 and ready to install SharePoint.

Step 3: Install SharePoint 2010

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 SQL Server 2008 KB 970315 x64 hotfix SQL_Server_2008_SP1_Cumulative_Update_2 build
10.00.2714.00 which you get to by clicking the View and request hotfix downloads link at the top of the KB article.

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 known issue on Win 7 64 according to this post.

After that successfully installed I rebooted again.

Now you need to run the SharePoint Configuration wizard, Start –> Programs –> Microsoft SharePoint 2010 Products –> SharePoint 2010 Products Configuration.

Note to domain users: 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. ;-)

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 I found a thread 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. ;-)

You made it! SharePoint 2010 Beta should now be installed. To verify, open your browser to http://<MachineName> and you should be able to start playing with your new SharePoint site.  

Installing Visual Studio 2010 Beta 2


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

You’ll need Visual Studio 2010 Beta Professional edition or higher to work with Office & 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.

Download Visual Studio 2010 Ultimate (web bootstrapper) (See this page for more download options).

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 Visual Studio 2010 Beta 2 Readme, Visual Studio 2010 Product Information and Featured Overviews and Walkthroughs.

 
Installing Microsoft Office 2010 Beta


This one is probably the easiest to install.

Download Office 2010 Beta here.

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 “Download the 32-bit (x86) version:” but the download will include both 32-bit and 64-bit so don’t worry.

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.

Let ‘er Rip!spsite

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 run as Administrator. 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.

You should also explore some of the awesome new project templates under the Office > 2010 and SharePoint > 2010 nodes in the File > New Project dialog.

What’s Next?

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:

Office 2010 Development Resources

SharePoint 2010 Development Resources

  • SharePoint Development in Visual Studio 2010 Walkthroughs
  • SharePoint Development in Visual Studio 2010 Videos
  • SharePoint Development Forums
  • SharePoint 2010 Development Resources
  • SharePoint Team Blog

    Enjoy!

     

  • Postedby Beth Massi | 7 Comments    
    More Posts Next page »

    This Blog

    Syndication

    Page view tracker