April, 2010

  • Visual Studio SharePoint Development Blog

    Walkthrough of creating a SharePoint 2010 external list using Visual Studio 2010

    • 6 Comments

    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

  • Visual Studio SharePoint Development Blog

    How to deploy a custom content master and use it in an application page

    • 6 Comments

    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.
    2. Create and deploy a site definition that uses the content master created in step #1 and create a site based on it. [Creating a site definition is just for illustration and is not necessary if you are modifying an existing Site to point to a new content master.]
    3. Create an application page to be deployed to the site created in step #2

    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

     

  • Visual Studio SharePoint Development Blog

    Building Visual Studio SharePoint Projects using Team Foundation Build

    • 6 Comments

    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:

    Set-ExecutionPolicy RemoteSigned

    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

  • Visual Studio SharePoint Development Blog

    Visual Studio 2010 & .NET Framework 4 RTM is Available

    • 0 Comments

    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.

    • Visual Studio 2010 allows users target of the right platform for their application, including Windows 7, Windows Server 2008 R2, SQL Server 2008, SharePoint. Office, Windows Azure, and Windows Phone 7 applications using their existing skills.
    • Visual Studio 2010 is a rich, personalized development environment.  We know that software developers spend much of their time in the IDE, and features like the new editor and multi-monitor support make your time in Visual Studio more productive and enjoyable.
    • Teams are able to work more efficiently using Application Lifecycle Management tools.  We’ve done a great deal of work in Visual Studio 2010 to improve testing and debugging tools.  Features like IntelliTrace and easy project management help your team ensure high quality.

    In addition to these features, there are a number of new features available for building SharePoint 2010 solutions.  Here are some of those:

    • Complete integration of SharePoint projects within the Visual Studio Integrated Development Environment (IDE).
    • Project templates for creating the most common SharePoint 2010 solutions such as Visual Web Parts, Workflows, Business Connectivity Services (BCS) external content types, Event Receivers, List Definitions, site Definitions, and many more.
    • Project templates which enable declarative artifacts and reusable workflows that were created in SharePoint Designer (SPD) 2010 to be imported into Visual Studio 2010 and then be included in a SharePoint project.  These artifacts and workflows can be modified as needed after they are imported and/or added to existing projects.
    • SharePoint developers have first class access to source code control, code analysis, and many other application lifecycle management features of both Visual Studio 2010 and Team Foundation Server 2010.
    • Item templates for common SharePoint 2010 artifacts such as Web Parts, Application Pages, List Instances, Content Types, Workflow Association & Initiation Forms, Resource files and others.  There is also a generic Empty Element which can be used to create any SharePoint artifact that may be needed.
    • Visual designers for building Web Parts, Workflows, and BCS external content types.
    • Robust packaging and deployment is supported which allows you to add SharePoint items to your project and then press F5 to debug your solution without having to worry about how the items are packaged into features.  Designers are provided for when you want to change the default feature(s) and packaging, in addition to a Packaging Explorer which shows all of the packages, features, and items across all of the projects in the solution.
    • A number of wizards which make creating projects and adding items easier, including support for Sandboxed solutions.
    • Numerous project, item, and file properties which allow the developer to have precise control over how each item/file is packaged and deployed.
    • Connections can be added now to the Server Explorer for any of the site collections on your local SharePoint 2010 server which allows you to quickly see what artifacts exist on the server from within the Visual Studio IDE.
    • Configurable and extensible deployment options for complete control over deployment of the packaged solution.
    • Robust extensibility is available throughout the new SharePoint project system and tools.

    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

  • Visual Studio SharePoint Development Blog

    Deploy a BDC Model project to SharePoint Foundation 2010 using Visual Studio 2010

    • 22 Comments

    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:

    1. In Visual Studio 2010, create a BDC project (read this post to learn how) or open your existing BDC project (e.g. “BdcModelProject1”).
    2. Add Feature Event Receiver to BDC project. In Solution Explorer, add a new Feature Event Receiver by right clicking on the feature (Feature1 in this sample) under Features folder and selecting Add Event Receiver.
    3. Write code for the Feature Event Receiver. In the generated code file (the default name is Feature1EventReceiver.cs/vb), replace the code with the sample code (Download here).
    4. Add reference.
      1. Copy Microsoft.BusinessData.dll assembly out of GAC. To do so: Start->Run, type in C:\Windows\assembly\gac_msil. Find Microsoft.BusinessData folder, and then copy Microsoft.BusinessData.dll to folder C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI.
      2. Add the following two assembly references to your project:
        1. In .Net tab, select Component Name = System.Web, Version=2.0.0.0.
        2. In Browse tab, navigate to folder C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI, and then add Microsoft.SharePoint.dll and Microsoft.BusinessData.dll.
    5. Set BDC SPI (SharePoint item) property. In Solution Explorer, select the SPI folder (e.g. “BdcModel1”), open Properties Window and update the following two Feature Receiver properties:
    6. 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

    7. Set Feature property. In Solution Explorer, expand Features\Feature1 folder, double click on Feature1.Feature and open Properties window and update the following Feature property:

      C# Project -
      - Receiver Class = BDCModelReceiver.Features.Feature1.ImportModelReceiver
    8. VB Project -
      - *Receiver Class = BdcModelProject1.BDCModelReceiver.Features.Feature1.ImportModelReceiver
      * Replace “BdcModelProject1” with your own project name

    9. Now you can deploy the BDC project (Project->Deploy) or debug the BDC project (F5) to SharePoint Foundation 2010. You will find the external content type being deployed to the metadata store.

    For more information about Business Connectivity Services, please also check out BCS Team blog.

    Rong Lu

Page 1 of 1 (5 items)