Web Part Platforms and Development TechniquesJan Tielens
Applies to:U2U
Web Parts are a great opportunity for developers to customize SharePoint, both to extend the existing functionality and to bring functionality or data coming from external applications in SharePoint sites. You can say that web parts are the building blocks for a SharePoint site. Since web parts are around for quite some time now, and you can develop web parts by using more than one technique, it can be hard for developers to decide how to build their web parts. This article is discussing the different development techniques and web parts platforms available today and in the near future. Contents: A Little Bit of History
Web Parts were introduced in SharePoint 2001, but really kicked off in the SharePoint 2003 release. Developers could now build the building blocks for SharePoint sites in managed .NET code, making use of the brand new .NET 1.1 Framework. This inspired the market and lots of companies developed 3rd party web parts to extend SharePoint, both commercial web parts and free web parts. Lots of those web parts can be found in the Web Component Directory on the Microsoft site (
http://www.microsoft.com/sharepoint/downloads/components/default.asp
).
When the next version of the .NET Framework was released, version 2.0, it got a little bit confusing: in ASP.NET 2.0 developers also could develop web parts and web part pages, without making use of SharePoint technology. The concepts were the same, but the technology was completely different. Web Parts developed for SharePoint 2003 could not be used in ASP.NET 2.0 web part pages, and vice versa. With the coming release of the 2007 Microsoft Office System the two different web part worlds will grow together, since you’ll be able to use both web part technologies without any problems.
![]() The Web Part Platforms
Before we start discussing the way how you can develop web parts, first let’s take a look at the different platforms which can run web parts:
SharePoint 2003: WSS v2 and SPS
In this category of products we can find Windows SharePoint Services version 2 (WSS v2) and Microsoft Office SharePoint Portal Server 2003 (SPS or SPS 2003). WSS v2 shipped as a part of the Windows Server 2003 release, and can be considered as a component of the operating system. It can be installed for free on top of Windows Server 2003 and provides collaboration and communication services connect people, information, processes, and systems. SharePoint Portal Server is a layer on top of the WSS v2 stack and enables enterprises to develop an intelligent portal that seamlessly connects users, teams, and knowledge so that people can take advantage of relevant information across business processes to help them work more efficiently. Additional features that can be found in SPS compared to WSS are for example: content targeting, enterprise search, profiles, audiences etc. Both WSS v2 and SPS make use of the .NET Framework version 1.1.
SharePoint 2003: WSS v2 with Service Pack 2
A little bit after the release of the .NET Framework version 2.0, the second service pack for WSS v2 was released. This service pack included some bug fixes and additional features as usual, but it also enabled WSS v2 to run on top of .NET 2.0 (but not necessarily). Notice that this only applies to Windows SharePoint Services; there is also a Service Pack 2 for SharePoint Portal Server, but this service pack does not allow SPS to run on .NET 2.0.
ASP.NET 2.0
Whit the release of ASP.NET 2.0 developers had the possibility to develop web parts and web part pages without making use of SharePoint technology. So basically almost the complete web part infrastructure and functionality was taken from SharePoint and ported to the .NET Framework version 2.0. All the concepts that people know from the SharePoint world still stand in ASP.NET 2.0 (e.g. web part zones, web part galleries etc).
SharePoint 2007: WSS v3 and MOSS
Currently the next version of the SharePoint products is being released (Beta 2 at the time of writing). The successor of Windows SharePoint Services v2 is (code)named Windows SharePoint Services v3 (WSS v3) and the product that we know as SharePoint Portal Server is transformed into Microsoft Office SharePoint Server 2007 (MOSS or MOSS 2007). Do not see MOSS just as the successor of SPS, in fact it is the successor of SPS plus a lot of additional and new features (e.g. Excel Services, Forms Services).
![]() The Development Tools and Techniques
Since there are multiple target platforms for web parts, there are also multiple tools and techniques to write those web parts (even more than the number platforms). Most development techniques focus on one target platform, and some of them offer upgrade scenarios. The different development tools and techniques for building web parts are:
Visual Studio .NET 2003
If you use Visual Studio.NET 2003 to write code, that code will target version 1.1 of the .NET Framework, the same version that WSS v2 and SPS are using. The first way to develop web parts in VS.NET 2003 is the “traditional” way; you just create a class that inherits from the Microsoft.SharePoint.WebPartPages.WebPart base class. This base class can be found in the Microsoft.SharePoint.dll assembly which is available on all systems that are running WSS v2 or SPS. To speed up development you can install the
Web Part Templates for Visual Studio.NET 2003
which contains one project template (Web Part Library) and a couple of item templates (e.g. WebPart, ToolPart).
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
namespace DemoWebParts
{
/// <summary>
/// Summary description for HelloWorld.
/// </summary>
[ToolboxData("<{0}:HelloWorld runat=server></{0}:HelloWorld>"),
XmlRoot(Namespace="DemoWebParts")]
public class HelloWorld : Microsoft.SharePoint.WebPartPages.WebPart
{
/// <summary>
/// Render this Web Part to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void RenderWebPart(HtmlTextWriter output)
{
output.Write("Web Parts Rock!");
}
}
}
If you develop web parts the “traditional” way you’ll notice that you have to write code for everything, even for building the user interface. Developers that are used to building user interfaces (both web and windows UI’s) in VS.NET 2003 may find this difficult and cumbersome since they are used to work with the design time tools of VS.NET 2003. There is however a way to develop web parts by making use of the great VS.NET 2003 design time tools. The idea is to build a Web User Control in VS.NET 2003 and load this user control inside a wrapper web part. This technique is excellently described in Patrick Tisseghem’s article on the MSDN.BE site. To take this technique one step further you can also make use of a generic wrapper web part namely the SmartPart. This is a free web part which can host any ASP.NET Web User Control. For more information about this development technique you can read the article
Building Web Parts the Smart Way
, also available on the MSDN.BE site.
![]() Figure 1: A Web User Control in Visual Studio.NET 2003. Visual Studio 2005
When Visual Studio 2005 just was released, web parts developers could only dream about the new features of VS 2005 and .NET 2.0, since they only could use VS.NET 2003 to build web parts. Shortly after the release of .NET 2.0 Microsoft has released the Service Pack 2.0 for Windows SharePoint Services which enable WSS v2 to run on .NET 2.0. When your WSS site is running on top of .NET 2.0 you can also use the following development technique: you create a class in VS 2005 that inherits from the Microsoft.SharePoint.WebPartPages.WebPart base class which can be found in the Microsoft.SharePoint.dll assembly, just like you would do in VS.NET 2003. In fact you can just copy and paste the code from VS.NET 2003 to VS 2005 and recompile the web part in .NET 2.0. If you do so, you can make use of all the new features of the .NET Framework 2.0 such as generics, rich data binding in ADO.NET 2.0 etc. These web parts are called “hybrid” web parts because they derive from the SharePoint Web Part base class, but they are compiled in .NET 2.0.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.WebPartPages;
namespace DemoWebParts
{
public class HelloWorld: WebPart
{
protected override void RenderWebPart(System.Web.UI.HtmlTextWriter output)
{
output.Write("Web Parts Rock!");
}
}
}
You can also create Web User Controls in VS 2005, thus it’s possible to make use of the user control technique to develop web parts leveraging ASP.NET 2.0. The scenario is exactly the same as in VS.NET 2003: just create a web user control and wrap it in a web part or in the SmartPart.
![]() Figure 2: A Web User Control in Visual Studio 2005.
Finally, in VS 2005 you can also create pure ASP.NET 2.0 web parts. The code is comparable to the code that you need to write for a SharePoint web part. The big difference is that instead of inheriting from the SharePoint base WebPart class, you inherit from the ASP.NET base WebPart class.
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls.WebParts;
namespace DemoWebParts
{
class HelloWorld: WebPart
{
public HelloWorld()
{
this.Title = "Hello World";
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
writer.Write("Web Parts Rock!");
}
}
}
Visual Web Developer 2005
Visual Web Developer 2005 (VWD) is a free development environment targeted to the .NET Framework version 2.0. In this tool you can’t directly create web parts but you can create Web User Controls, subsequently you can leverage once again the user control technique to build user controls in VWD and wrap them in the SmartPart for example.
![]() The Matrix
We’ve discussed the different web part platforms and the development techniques. It’s quite obvious that you can’t just use any web part on any platform. The following matrix shows which combinations are supported.
Let’s go over all the development techniques and discuss on which platforms the web parts can be used: Visual Studio.NET 2003
Visual Studio 2005
Visual Web Developer 2005 Building user controls in VWD give you the same target platforms as building user controls in VS 2005. Thus all platforms can be used except WSS v3 (without SP2) and SPS 2003. ![]() Connectable Web Parts in ASP.NET and SharePointCreating connectable web parts is a very nice way to give your site users the opportunity to construct their own user interface with the building blocks you have provided. Not only they can determine the location of the web parts, but they can also define the relationships between them by connecting them. A good example of a connectable web part scenario is the master/detail view: one web part is showing a list of all the orders, and another web part is showing a list of all the order lines. If those web parts are connectable the order list web part can send the selected order ID to the order lines web part so it can show only the lines of the selected order. The way you create connectable web parts in the SharePoint world and in the ASP.NET world is quite different. If you create a web part for SharePoint 2003 you need to implement one of the interfaces defined in the Microsoft.SharePoint.dll, for example ICellConsumer, ICellProvider, IRowConsumer, IRowProvider and so on. SharePoint will check your web part class, if the interface is available the web part supports connections. In the ASP.NET 2.0 the connections framework is totally different. Instead of using an interface defined in the Microsoft.SharePoint.dll, first you have to build your own interface that describes the data that is going to be communicated between the provider web part and the consumer web part. Than both the provider and the consumer web part need to register that interface so ASP.NET 2.0 allows to make the connection. The 2007 Microsoft Office System supports both the connectable frameworks: so you will be able to use SharePoint 2003 connectable web parts and ASP.NET 2.0 connectable web parts. // The connection interface
namespace Microsoft.Sample.WebParts
{
public interface ITextCommunication
{
string Text { get;}
}
}
// A sample consumer web part
namespace Microsoft.Sample.WebParts
{
public class TextDisplayWebPart : WebPart
{
// web part implementation left out
[ConnectionConsumer("Text Consumer")]
public void GetInterfaceForConnection(ITextCommunication provider)
{
_provider = provider;
}
}
}
// A sample provider web part
namespace Microsoft.Sample.WebParts
{
public class TextInputWebPart : WebPart, ITextCommunication
{
// web part implementation left out
[ConnectionProvider("Text Provider")]
public ITextCommunication ProvideInterfaceForConnection()
{
return this;
}
}
}
![]() Resources
SmartPart
Service Pack 2 for WSS v2
Building Web Parts the Smart Way
Building Web Parts for Microsoft SharePoint Products and Technologies
Building Web Parts for Microsoft SharePoint Products and Technologies: Part III - Connectable Web Parts
Building Web Parts with User Controls
MSDN Office Developer Center
![]() About the author
| |||||||||||||||||||||||||||||||||||||||||