There are a bunch of SharePoint features in Visual Studio 2010. You may have already heard about them from reading the blog Short Overview of SharePoint Features in Visual Studio 2010 or by other means. Today I want to introduce one of them, Business Data Connectivity (BDC) designer, which is available in the project template Business Data Connectivity Model. If BDC is new to you, here is a short description. BDC is one of two most important architectural components of Microsoft Business Connectivity Services (BCS) which enables users to read and write data from external systems—through Web and Windows Communication Foundation (WCF) services, databases, and Microsoft .NET Framework assemblies—from within Microsoft SharePoint 2010 and Microsoft Office 2010 applications. This MSDN webpage Business Data Connectivity (BDC) Service has a more descriptive version.
Visual Studio 2010 helps a SharePoint developer to develop, debug and deploy .NET assemblies as external data sources to SharePoint. In the following paragraphs, I will walkthrough with you how to create your first SharePoint external list using Visual Studio 2010. In order to make this walkthrough work on your machine, you need to install SharePoint 2010* and Visual Studio 2010#.
*: Please read Setting Up the Development Environment for SharePoint Server before the installation. If you are using SharePoint Foundation 2010 you will need to create a Feature Event Receiver to enable the import of BDC models. How to create a Feature Event Receiver will be covered in a future blog post.
#: Please make sure Microsoft SharePoint Development Tools component is selected when installing. It is chosen by default if you choose Full installation.
Let’s start the journey.
1. Create a new BDC Model project. (Main menu: File -> New -> Project…). In the left column of the New Project dialog, you are able to find node 2010 under tree view Visual C# -> SharePoint. Similarly you can find same node under Visual Basic -> SharePoint. In the middle column of the dialog, you should be able to see Business Data Connectivity Model listed as one of the project templates. See the screenshot as follows. Here I am creating BDC Model project in Visual C#. You are able to do the same things in Visual Basic.
2. After clicking [OK] button in the New Project dialog, the SharePoint Customization Wizard dialog will be displayed. In this dialog you can customize the local site you want to target and trust level for the SharePoint solution. Since a BDC model is deployed to a farm, a collection of one or more SharePoint servers and one or more SQL servers, only “Deploy as a farm solution” option is enabled. Here is the screenshot of the dialog.
3. When you click [Finish] button in the SharePoint Customization Wizard dialog, the BDC Model project will be created. There are four main UI panes that help you manage the BDC model visually. They are the BDC Designer Surface, BDC Method Details Pane, BDC Explorer, and Properties Browser.
a. The BDC Designer Surface allows editing entities, identifiers, methods, and associations between entities. And you can do that either from toolbox or context menus.
b. The BDC Method Details pane, where its name is already self-explanatory, lets you edit everything related to a method, from the method itself, its parameters to its parameters’ type descriptors, from method instances to filter descriptors, etc.
c. BDC Explorer lists and organizes metadata objects in the BDC model in a tree view. It lets you to browse and search metadata objects in a graphical way and allows you to copy/cut/paste type descriptors between different parameters or type descriptors.
d. Properties Browser gives you a familiar way of editing components and attributes of BDC Models. We use it to supplement the functions offered by the other three panes and list all the attributes for a particular metadata object for editing. Here is a typical layout of a BDC Model project as described above.
4. If you notice, there is already a default entity generated for you when the project is created. This default entity also has an identifier and two methods ReadItem and ReadList created. One is a Finder method that is to return a collection of data. The other is a Specific Finder method that is to return a specific entry based on the input parameter(s).
5. Now let’s deploy to the SharePoint server. You can either click the deploy menu item in main menu (Build -> Deploy Solution), or in the context menu of the project or the solution. In the output you will see several activities happening including packaging, solution retraction/addition, deployment, etc.
6. Let’s open the target site and see if our model has been successfully deployed. Open the target site with any browser supported by SharePoint, like Internet Explorer 8. Create an external list based on the model we just deployed. Here are the steps to create an external list in case you are new to it.
a. In main menu: Click Site Actions -> More Options…
b. On the Create dialog, select External List, click [Create] button in the right column
c. On the next external list create form, type a name for the list. Check ‘Yes’ to display the list on the Quick Launch for easy access. Then click to select the model we just deployed in the External Content Type Picker form. Click [Create] on the external list create form. Now the Hello World list is displayed.
In the main menu under List Tools -> Items, you may find only “View Item” option is enabled. Guess why? Yes, it is because the default entity only has a Finder method to view the entire list and a Specific Finder method to view a specific item. In our next blog in this series, we will show you how to add more functions like Add, Update and Delete to the list as well as pull data from external data sources.
Jeff Chen
In SharePoint 2007, Application Pages would inherit from Application Master deployed to Layouts folder. The Site Pages would inherit from a different Site Master deployed to SharePoint Content database. Since there was no way for application pages to inherit from the same master as that of the site pages, the look and feel of the two kinds of pages in a SharePoint application would be different, by default. This problem is overcome in SharePoint 14 with the introduction of Dynamic Master Page feature.
Application Pages that wants to inherit from site master will have to specify DynamicMasterPageFile attribute instead of the MasterPageFile attribute in the Page directive as
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ApplicationPage1.aspx.cs" Inherits="SharePointProject15.Layouts.SharePointProject15.ApplicationPage1" DynamicMasterPageFile="~masterurl/default.master" %>
DynamicMasterPageFile attribute can only take two tokens as values; ~masterurl/default.master or ~masterurl/custom.master. These tokens will be resoved by SharePoint at runtime to point to the site's default master and the site's custom master respectively.
Deploying a custom content master page and using it in an application page involves three steps:
1. Create and deploy a custom content master.
1.1 Create a C# empty SharePoint project with all default selections and add a module element with name "MasterPage" to it.
1.2 Delete the sample.txt by right clicking on it in the solution explorer and selecting delete
1.3 In Solution Explorer, Right click the "MasterPage" module folder and add a file with name MyCustomContent.master (For example you can add a text file and change the extension from .txt to .master) and add the content to this file. Or you can start with SharePoint's existing content master and modify as needed. For simplicity let us choose an existing content master and proceed with it. To do this, go to master page gallery in SharePoint. Click on the dropdown of the master page you wish to save for example. Minimal.Master and select "Send To" and then "Download a Copy" and save the file.
Right click the "MasterPage" module folder and select "Add Existing" to add the saved master page. Be sure to change the name of the master page (say for example MyCustomContent.master) to avoid overwriting the SharePoint created master page. Double click on the master page to open it in the default editor and make the necessary modifications to the master page. In order to demonstrate the active master page is the new custom master in a simple way, let us change the ContentPlaceHolder with Id "PlaceHolderMain" to "PlaceHolderMyCustomMain".
1.4 Modify the element file associated with the module as follows:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="MasterPage" Url="_catalogs/masterpage">
<File Path="MasterPage\MyCustomContent.master" Url="MyCustomContent.master" />
</Module>
</Elements>
1.5 Right click the project in the solution explorer and select Deploy.
1.6 Verify that the master page got deployed to the master page gallery.
2. Create and deploy a site definition that uses the content master created in step #1 and create a site based on it.
2.1 Create a C# SharePoint Site Definition project called "MyCustomSiteDefinition".
In the onet.xml that gets created as part of the Site Definition project modify the configuration element so that the MasterUrl and CustomMasterUrl points to the newly deployed custom content master, as follows
<Configuration ID="0" Name="MyCustomSiteDefinition" MasterUrl="/_catalogs/masterpage/MyCustomContent.master" CustomMasterUrl="/_catalogs/masterpage/MyCustomContent.master">
Since we have changed the PlaceHolderMain to PlaceHolderMyCustomMain, we will also have to change it in the default.aspx. If we miss this step, SharePoint will throw error when we create a site based on this site definition.
2.2 Open the default.aspx file in the Site Definition project and change the ContentPlaceHolderId attribute in the default.aspx file to "PlaceHolderMyCustomMain" as shown below.
2.3 Right click the Site Definition project in the solution explorer and select Deploy.
2.4 In SharePoint, Click Site Actions | New Site. Select SharePoint Customizations link on the left navigation, enter the title and Url name for your site (example MyCustomSite)
2.5 Click on Create to create the site.
3. Create an application page to be deployed to the site created in step #2.
3.1 Create a C# Empty SharePoint project with local site used for debugging pointing to the site created in step #2 which is http://<machineName>/MyCustomSite.
Choose the option to Deploy as a farm solution. This is required since application pages can only be deployed to layouts folder and not to content database.
3.2 Click Finish and add an Application Page to the project. Right click on the Application Page and select "Set as Startup Item" to set it as startup item.
By default, it shows a warning since the active master page does not have "PlaceHolderMain" defined. If you invoke the IntelliSense, the new placeholder can be seen.
This application page inherits the newly deployed content master and the IntelliSense reflects the same. Press F5 to deploy it and view it in SharePoint. You can see that the look and feel of this page is inherited from the new custom content master.
Pallavi Vajranabhaiah
With Microsoft’s introduction of the Visual Studio 2010 SharePoint Developer Tools and its continually growing support for team development, the SharePoint Developer Tools team has published an MSDN article on how to configure your Team Foundation Build server(s) to support both the building of Visual Studio SharePoint projects and the creation and validation of SharePoint deployment packages (.wsp).
The article outlines the steps needed for setting up both Team Build 2008 and Team Foundation Build 2010 server configurations.
Additionally, the team has also created a PowerShell script that will aid users in collecting and installing the required assemblies for build Visual Studio SharePoint projects. The steps to use the PowerShell script are quite simple.
First, download the .ps1 file from the MSDN Code Gallery and copy it onto a SharePoint Tools developer’s machine or any machine that has Visual Studio 2010 and SharePoint 2010 installed. Before you can execute the script, you need to enable the correct permissions. To do so, run PowerShell under administrator privileges and enter the following command:
Set-ExecutionPolicy RemoteSigned
Next, navigate to the directory where you copied the .ps1 script and enter the following command
.\ SharePointProjectToTfsBuildServer.ps1 –Collect
This will gather all the necessary files from the developer’s machine and copy them into a sub folder named “Files”. Copy this subdirectory, along with the PowerShell script onto the build server(s).
Finally, the last step is to tell the PowerShell script to install the files. Once again, we’ll need to enable the correct permissions to execute the script so again run PowerShell as an administrator and enter the following command:
Next we’ll do the same thing we did when we “collected” the required assemblies but instead of passing the “-Collect” parameter, we’ll pass it “-Install”, like so:
.\ SharePointProjectToTfsBuildServer.ps1 –Install
This moves all the files into the correct place and makes any other changes to the system, if needed.
Now you’re all set to begin building your Visual Studio SharePoint projects on your Team Build server(s). Consult the MSDN article for more information on how to correctly set up your build definition in TFS.
Scot Moorhead
We are very excited to announce the availability of Visual Studio 2010 and .NET Framework 4 on April 12th. This represents the biggest tools release from Microsoft in many years.
As mentioned in Somasegar’s recent blog post, the new release of Visual Studio 2010 has plenty of compelling new features and updates that will make every developer more productive.
In addition to these features, there are a number of new features available for building SharePoint 2010 solutions. Here are some of those:
To purchase Visual Studio 2010 now, visit here. If you are an MSDN subscriber, later in the day on April 12th you can download Visual Studio 2010 from MSDN.
Mike Morton
Business Connectivity Services (BCS), one of the key components of SharePoint 2010, helps you to access external line-of-business (LOB) data. The SharePoint team posted a blog entry which demonstrates how to create your first BDC (Business Data Connectivity) model using Visual Studio 2010. As indicated in the post, you can use Visual Studio 2010 to deploy your BDC model to Microsoft SharePoint Server 2010.
However, if you are using Microsoft SharePoint Foundation 2010 on your develop machine, or you want to make the model deployable to Microsoft SharePoint Foundation 2010 on other machines, you will need to write a Feature Event Receiver to enable the deployment of BDC models from within Visual Studio 2010. In this blog post, I’ll show you how to create a Feature Event Receiver to do so.
Here are the detailed steps:
C# Project - - Assembly = $SharePoint.Project.AssemblyFullName$ - Class Name = BDCModelReceiver.Features.Feature1.ImportModelReceiver
VB Project – - Assembly = $SharePoint.Project.AssemblyFullName$ - *Class Name = BdcModelProject1.BDCModelReceiver.Features.Feature1.ImportModelReceiver * Replace “BdcModelProject1” with your own project name
VB Project - - *Receiver Class = BdcModelProject1.BDCModelReceiver.Features.Feature1.ImportModelReceiver * Replace “BdcModelProject1” with your own project name
For more information about Business Connectivity Services, please also check out BCS Team blog.
Rong Lu