SharePoint 4 Developers

Additional reference guide in .NET / SharePoint Development

Article published in the .net Magazine

The article shows the reader an introduction to the Web Parts and how to develop Visual Web Parts for SharePoint 2010, showing the development with Visual Studio 2010 and how to take advantage of the features this tool offers.

Hi folks,

I would like to inform that in this .net Magazine - issue 80, my exclusive article about WebPart development in SharePoint 2010 was published. Here are more details:

What is this about

The article shows the reader an introduction to the Web Parts and how to develop Visual Web Parts for SharePoint 2010, showing the development with Visual Studio 2010 and how to take advantage of the features this tool offers.

What is it for

One way to customize Web sites and portals in SharePoint is by adding Web Parts. Visual Studio 2010 now becomes a powerful ally in SharePoint 2010 development and brings new templates for development. Visual Web Parts are among these new templates that make the developer's work easier.

In which situation the subject is useful

With the release of SharePoint 2010 lots of .NET developers may begin developing in this platform easily and without trouble, unlike the previous versions that made the arise of new developers difficult. This article brings an approach to .NET developers who want to take advantage of the new features of Visual Studio 2010 to develop SharePoint 2010 solutions.

I think you'll like it! On sale now!

Link to the magazine:


Marcel Medina

Click here to read the same content in Portuguese.

Customising Form Templates

How to customise Form Templates in SharePoint 2010? The author shows 3 approaches in performing that.

Hi folks,

I have found interesting things in SharePoint Server 2010 after the MOSS 2007 migration project I have worked on recently. Check this out, can you identify the difference between Figures 1 and 2 below?

Figure 1 - Document Content Type

Figure 2 - Report Content Type

It seems obvious isn't it? Save and Cancel buttons are more evident, but the main difference that affects users is the content type choice field.

In the Figures 1 and 2 the content types Document and Report were used. Each one refers to a different Form Template.

Note: For comparative purposes I have excluded the other Report columns not displayed in Figure 2.

What to do if you need to make the Content Type Choice Field available (Figure 1)? I'll show you some approaches to change that.

Approach 1 - SharePoint Manager 2010

This tool is great because it facilitates the work, helping you to the rapid update of SharePoint objects. If you are a SharePointer, you should know it!

When using this tool any update is very simple to be applied, which is displayed in the Figure 3 for the update of the Form Template:

Figure 3 - Updating the Form Template

The Form Template called RptLibraryForm is responsible for not displaying the content type choice field (Figure 2). As per Figure 3, the solution would be to update the attributes DisplayFormTemplateName, EditFormTemplateName and NewFormTemplateName to another form template, i.e.: DocumentLibraryForm (which is the same as shown in Figure 1).

Form templates are found in content types and they can be changed in two places: the root site collection or document libraries. This type of change would be recommended only for direct change in document libraries, because I do not recommend changing the base object of a root site collection. Any mistake at this level and will affect the site and sub-sites!

When things get complicated a more sustainable solution comes true, which involves the development of form templates.

Approach 2 – Script

A script can be created by using Visual Studio with the creation of a Console Application or via PowerShell.

Regardless of the way it will be executed, the result is the same as the use of SharePoint Manager 2010, but will be done via script.

The code below was developed to run via Console Application:

Code Snippet
  1. static void Main(string[] args)
  2. {
  3.     using (SPSite site = new SPSite(""))
  4.     {
  5.         using (SPWeb web = site.RootWeb)
  6.         {
  7.             // Get the library
  8.             SPDocumentLibrary library = web.Lists["Sample"] as SPDocumentLibrary;
  10.             // Change the form template
  11.             library.ContentTypes["Report"].DisplayFormTemplateName = "CustomLibraryForm";
  12.             library.ContentTypes["Report"].EditFormTemplateName = "CustomLibraryForm";
  13.             library.ContentTypes["Report"].NewFormTemplateName = "CustomLibraryForm";
  15.             // Update the content type
  16.             library.ContentTypes["Report"].Update();
  17.         }
  18.     }
  19. }

NOTE: The code above is updates a Document Library Content Type.

This is the Powershell script that matches the Console Application:

Figure 4 – Powershell script

Download the script here.

Approach 3 - Development of Form Templates

A safe solution is the development of features in SharePoint, because the generated packages can be easily added and activated. Likewise when not in use, disabled and removed.

I recommend sustainable approaches, as they will run smoothly and will not bring you headaches in the future.

Create a new solution in Visual Studio 2010 and name it CustomLibraryFormSolution, as shown in Figure 5:

Figure 5 – New Solution

Define the solution as a Farm Solution, validate it and wait for its creation by the Wizard, as per Figure 6:

Figure 6 – Wizard

After creating the project a User Control and Feature needs to be created for deployment.

Creating the User Control CustomLibraryForm

This User Control represents a new form template that will be created. To begin add the SharePoint Mapped Folder 14\TEMPLATE\CONTROLTEMPLATES in your project, as displayed in the Figure 7:

Figure 7 – SharePoint Mapped Folder

Note: SharePoint Mapped Folders help a lot. They deploy any file automatically and in the correct place.

Then add a new User Control in this mapped folder and name it CustomLibraryForm, as per Figure 8:

Figure 8 – User Control that holds the Form Template

NOTE: If you open the folder 14\TEMPLATE\CONTROLTEMPLATES you can see that it contains several User Controls. The main form templates in use are concentrated in the file DefaultTemplates.ascx.

Delete the files .cs and leave only the .ascx available. Open the User Control, delete all the content and add the code below:

Code Snippet
  1.    <%@ Control Language="C#"AutoEventWireup="false" %>
  2. <%@Assembly Name="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
  3. <%@Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.WebControls"%>
  4. <%@Register TagPrefix="ApplicationPages" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.ApplicationPages.WebControls"%>
  5. <%@Register TagPrefix="SPHttpUtility" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.Utilities"%>
  6. <%@ Register TagPrefix="wssuc" TagName="ToolBar" src="~/_controltemplates/ToolBar.ascx" %>
  7. <%@ Register TagPrefix="wssuc" TagName="ToolBarButton" src="~/_controltemplates/ToolBarButton.ascx" %>
  9. <SharePoint:RenderingTemplate id="CustomLibraryFormCore" runat="server">
  10.     <Template>
  11.             <table class="ms-formtable" style="margin-top: 8px;" border="0" cellpadding="0" id="formTbl" cellspacing="0" width="100%">
  12.             <SharePoint:ChangeContentType runat="server"/>
  13.             <SharePoint:DocumentLibraryFields runat="server"/>
  14.             <SharePoint:ApprovalStatus runat="server"/>
  15.             </table>
  16.             <SharePoint:WebPartPageMaintenanceMessage runat="server"/>
  17.             <SharePoint:DocumentTransformersInfo runat="server"/>
  18.             <table cellpadding="0" cellspacing="0" width="100%"><tr><td class="ms-formline"><img src="/_layouts/images/blank.gif" width='1' height='1' alt="" /></td></tr></table>
  19.             <table cellpadding="0" cellspacing="0" width="100%" style="padding-top: 7px"><tr><td width="100%">
  20.             <SharePoint:ItemHiddenVersion runat="server"/>
  21.             <SharePoint:InitContentType runat="server"/>
  22.             <wssuc:ToolBar CssClass="ms-formtoolbar" id="toolBarTbl" RightButtonSeparator="&amp;#160;" runat="server">
  23.                 <Template_Buttons>
  24.                     <SharePoint:CreatedModifiedInfo runat="server"/>
  25.                 </Template_Buttons>
  26.                 <Template_RightButtons>
  27.                     <SharePoint:SaveButton runat="server"/>
  28.                     <SharePoint:GoBackButton runat="server"/>
  29.                 </Template_RightButtons>
  30.             </wssuc:ToolBar>
  31.             </td></tr></table>
  32.     </Template>
  33. </SharePoint:RenderingTemplate>
  35. <SharePoint:RenderingTemplate id="CustomLibraryForm" runat="server">
  36.     <Template>
  37.             <SharePoint:InformationBar runat="server"/>
  38.             <wssuc:ToolBar CssClass="ms-formtoolbar" id="toolBarTbltop" RightButtonSeparator="&amp;#160;" runat="server">
  39.                 <Template_RightButtons>
  40.                     <SharePoint:SaveButton runat="server"/>
  41.                     <SharePoint:GoBackButton runat="server"/>
  42.                 </Template_RightButtons>
  43.             </wssuc:ToolBar>
  44.             <SharePoint:FormToolBar runat="server"/>
  45.             <SharePoint:FormComponent TemplateName="CustomLibraryFormCore" runat="server"/>
  46.     </Template>
  47. </SharePoint:RenderingTemplate>

NOTE: The code above was extracted from the User Control RptLibTemplate.ascx. Line 12 was the only line added that includes the Content Type Choice field.

Creating the Custom Report Feature

This feature will be responsible for the deployment of a Content Type which uses the new Form Template created. To begin add a new content type and name it CustomReport, as per Figure 9:

Figura 9 – New Content Type

The Wizard will appear according to the Figure 10, then select the base content type in which the new content type will inherit from.

Figure 10 – Wizard

After its creation the Content Type XML definition is automatically displayed, modify it according to the code below:

Code Snippet
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Elements xmlns="">
  3.   <!-- Parent ContentType: Report (0x01010058DDEB47312E4967BFC1576B96E8C3D4) -->
  4.   <ContentType ID="0x01010058DDEB47312E4967BFC1576B96E8C3D4006440fbf80e1849a8bc00166a8703769d"
  5.                Name="Custom Report"
  6.                Group="Business Intelligence"
  7.                Description="References a Custom Form Template"
  8.                Inherits="FALSE"
  9.                Version="0">
  10.     <FieldRefs/>
  11.     <XmlDocuments>
  12.       <XmlDocument NamespaceURI="">
  13.         <FormTemplates xmlns="">
  14.           <Display>CustomLibraryForm</Display>
  15.           <Edit>CustomLibraryForm</Edit>
  16.           <New>CustomLibraryForm</New>
  17.         </FormTemplates>
  18.       </XmlDocument>
  19.     </XmlDocuments>
  20.   </ContentType>
  21. </Elements>

NOTE: Make sure that the line 8 is changed to Inherits = "FALSE", once it prevents the Form Template informed in the section XMLDocuments to be overwritten by inheritance. Interestingly even setting this attribute to false, the columns are automatically inherited. :)

A feature should be designed to deploy the content type. Add it on the project and set its attributes as shown in Figure 11:

Figure 11 – Custom Report Feature Details

Before anything, make sure the checkbox Reset Web Server, which is available at the package properties, is checked. It assures that the User Control is identified immediately after the deployment, check out the Figure 12:

Figure 12 – Package details

NOTE: Download the solution here.

Custom Form Template

In the end, when the form template is created and deployed, according to the Figure 13 check the expected CustomLibraryForm:

Figure 13 – Custom Form Template

NOTE: As you can see, this is the form RptLibraryForm with the addition of the Content Type Choice field.

The three approaches used work very well. As already said, always use best practices and create sustainable solutions.

Unlike the creation of features, scripts are developed faster, although in this case it is a temporary solution. I say this because in the future something can "break" according to the script run (with or without documentation).

I hope it helps.



Marcel Medina

Click here to read the same content in Portuguese.

Business Connectivity Services – Part IV

Understand the hierarchical structure of the BDC metadata model (Business Data Connectivity Model) and the new tools in Visual Studio 2010 to design BDC models (Part IV)

Hi folks,

This is the fourth part of the article about the news in integrating external data with the Business Connectivity Services (BCS) in SharePoint 2010!

Just to recap, the Part I of this article brought an introduction to the BCS by the analysis of its architecture and components, the Part II brought the creation of External Content Types (ECT) via Database and the Part III the creation of ECTs via Web Service.

Part I reading is extremely important to understand this post. In this article I will explain the hierarchical structure of the Business Data Connectivity Metadata Model and introduce the new tools available in the Visual Studio 2010 to create BDC objects.

Have a good reading!

Understanding the BDC Metadata Model

In this article's example a new template in Visual Studio 2010 called Business Data Connectivity (BDC) Model will be used. It allows the creation of entities (BDC Entities) also known as External Content Types, an old friend of us (check Part I for more details).

Entities are objects that belong to the BDC metadata model and represent one of the core BDC metadata model objects. In this approach I want to go a little deeper into this model, check out the Figure 1:

BDCModelFigure 1 - BDC Metadata Model

Now it is clear where the ECTs are within the BDC Metadata Model, but we still do not know in details the role performed by each one of the objects comprised in the Figure 1. We can only note that the objects are in a hierarchical structure.

To understand these objects let's check the details of each one:

NOTE: The same content can be found in the Reference links, however I have decided to drill down a little bit more than the content presented on MSDN. :)

  • Model - This is the BDC core main object that maps the external data. This is the aggregator of all the objects that comprise the hierarchy of this model.

  • LobSystem - Inside the model it behaves as the representation of an external service that contains the business logic, simply by defining the type of external data source to be used, that can be:
  1. Database – Sets the mapping of a database;
  2. DotNetAssembly – Defines the mapping of an assembly. NET;
  3. Wcf – Defines the mapping of a WCF service endpoint;
  4. WebService – Defines the mapping of a Web Service. It is considered "deprecated", so use a WCF service;
  5. Custom – Defines the mapping of a custom connector, implemented to manage the external data source connection and data transferring.
  • LobSystemInstance - This is the implementation of a LobSystem. It holds all the connection details to an external service.

  • Entity - This is the representation within the BDC metadata model of an ECT, which according to the Part I describes the schema and data access capabilities of an external data source and its behaviour within Office and SharePoint.

  • Identifier - An identifier acts as a primary key in entities, the same concept used in tables.

  • Method - The methods are the behaviours of an entity. Within the metadata model it works as an aggregator of settings (FilterDescriptor, Parameter, MethodInstance) of the method that represents.

  • FilterDescriptor - Basically a FilterDescriptor can be created within a method to select both the input and the return of values. Several types of filters can be used (check the Reference links).

  • Parameter - Defines the parameter to be used inside the method, as follows:
  1. In – Used to input parameters;
  2. Out – Used to output parameters, similar to the parameter "out" in C#.
  3. InOut – Represents a parameter that has two functions (input / output), similar to the parameter "ref" in C#.
  4. Return – Sets a method return type. In the BDC this is considered as a return parameter.
  • TypeDescriptor - A TypeDescriptor is nothing more, nothing less than a definition to the parameter type. i.e.: Int32, String. It is recursive because it allows that other TypeDescriptor is referred as a parameter type.

  • MethodInstance - This is the implementation of a Method. Operations Create, Update, ReadItem, ReadList and Delete are already predefined for using.

  • Action - The actions allow the addition of extra functionalities to ECTs because they work as an additional link to external data. By default the actions View Item, Edit Item and Delete Item are added to the user interface (check the Reference links) and any further action added, such as a link to open a page, follows the ECT in any part of SharePoint.

  • ActionParameter - Sets the URL of the action that refers, so the link created works. It uses Identifiers or TypeDescriptors of the entity to create the URL.

  • AssociationGroup - Associations represent relationships between entities, similar to a relationship of tables. An AssociationGroup should be used to tie association methods, which are applied in a relationship of entities. i.e.: Given two entities Customer and Order, an AssociationGroup would store methods like GetOrderByCustomer and GetCustomerByOrder.

NOTE: In the next part of this lesson you will see the majority of these objects in use. This overview will be consolidated with a hands-on demo, especially when working with XML behind these definitions.

BDC Metadata Model Design Tool

Visual Studio 2010 was powered with several new design tools and the BDC was not forgotten. Now it's easy to create BDC models, because the toughest job (creation of objects) can be done visually and other small details manually in the XML generated.

The Figure 2 displays the new windows available in VS2010 to design BDC models:

NewDesignerFigure 2 - New windows to design BDC models

With the exception of the Properties window, three (3) new windows were added to the VS2010. They are:

  • BDC Designer - Enables the creation and edition of Entities, Identifiers, Methods and Associations between Entities. This is an design area that allows the creation of objects via drag-and-drop from the Toolbox window or even using the context menu (right mouse button).

  • BDC Method Details - As the name implies, it displays the configuration details of the methods. Allows creation and edition of methods, parameters, typedescriptors and filters (according to the BDC metadata model).

  • BDC Explorer - Organizes and displays BDC metadata model objects in a tree view. Its main purpose is to display objects in a hierarchical structure, but also allows the creation of TypeDescriptors and validation of objects.

Throughout the development in the next part you will see how to manipulate the BDC Metadata Model objects by using these panels. Stick around!



Marcel Medina

Click here to read the same content in Portuguese.