SharePoint Products and Technologies offer a wide variety of development possibilities. As explained earlier, SharePoint Products and Technologies offer built-in capabilities that enable collaboration and social computing, an enterprise portal platform, enterprise search, ECM, business process and forms, and business intelligence. The .NET Framework provides a set of tools that allow you to customize and extend these capabilities. As a .NET developer, you will find the set of components used to build enterprise solutions compelling. The following section of this article introduces you to different developer components or solution artifacts that you can use to get started with SharePoint development.
Web Parts
As we explained earlier, you can build SharePoint Web Parts just as you build Web Parts in ASP.NET. But in addition, site administrators can deploy your Web Parts to SharePoint sites. As part of a SharePoint site, your SharePoint Web Part is immediately available to end-users to add to pages or use to personalize pages.
For example, let's say you create a custom ASP.NET Web Part that displays driving directions based on a custom start point property that users can personalize. To create this Web Part, you create a custom class library project that contains a control that inherits from the System.Web.UI.WebControls.WebParts.WebPart class. In this class, you override the CreateChildControls method to control the rendering of HTML. After you finish the code of the class, you compile the project and add a reference to the Web Part project's .dll in your Web project. Finally, to display your Web Part in a Web Form, you add the control to a Web Part zone.
One advantage of developing ASP.NET Web Parts is that you can reuse them in SharePoint sites. Figure 4 shows a custom driving directions Web Part running in an ASP.NET 2.0 Web page and in a SharePoint site. Another advantage is that you can create Web Parts that provide a complete set of Windows SharePoint Services features, such as document services, events, workflow, search, site columns, content types, and more.
Figure 4. Custom Web Part running in ASP.NET 2.0 pages and a SharePoint site
For more information, see Working with ASP.NET 2.0 Web Parts and Windows SharePoint Services 3.0.
Data Lists
Windows SharePoint Services enables you to create lists and customize them to include specific columns of information. A list consists of items or rows, and columns or fields that contain data. With ASP.NET you must create or get access to a SQL Server database, and then create the tables and columns you need. Then, you have to build UI components to allow the users to populate the columns with this data. Windows SharePoint Services provides a user friendly foundation for managing data structures in the form of lists, and for doing data entry into these data structures.
Let's examine a scenario in which you are a consultant tracking many different development projects. Your manager asks you to create a custom list of projects and share the list by using intranet resources. Because your company has a SharePoint site, you decide to create a custom list that displays the title, delivery date, status, documentation, owners, and cost of each project. Figure 5 shows a custom "Projects" list.
Figure 5. Custom "Projects" list
Having this list in a SharePoint site allows you to share project information with your co-workers. Better yet, as a developer you can access data stored in this list programmatically. Windows SharePoint Services 3.0 provides a set of Web services and classes that allow users to access data from SharePoint lists.
In another scenario, you might want to create an ASPX page with a label control that returns items from the "Projects" list where values in the "Cost" field are greater than $5,000. You can display this information by adding the Microsoft.SharePoint namespace and Microsoft.SharePoint.Utilities namespace to the class code-behind file. Additionally, you need to write some code that can access the data stored in the "Projects" list, as shown in the following code example.
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack){
SPWeb oWeb = SPContext.Current.Web;
SPList oList = oWeb.Lists["Projects"];
SPQuery oQuery = new SPQuery();
oQuery.Query = "<Where><Gt><FieldRef Name='Cost'/>" +
"<Value Type='Number'>5000</Value></Gt></Where>";
SPListItemCollection collListItems = oList.GetItems(oQuery);
StringBuilder sb = new StringBuilder();
// The indenting of the following lines of code has been
// modified for readability. Please modify as
// needed.
foreach (SPListItem oListItem in collListItems){
sb.Append("Item: ");
sb.Append(SPEncode.HtmlEncode(Convert.ToString(oListItem["Title"])));
sb.Append("::Value: ");
sb.Append(SPEncode.HtmlEncode(Convert.ToString(oListItem["Status"])));
sb.Append("::Calculated: ");
sb.Append(SPEncode.HtmlEncode(ConvertToString(oListItem["Cost"])));
sb.Append("<BR>"); }
}
Label1.Text = sb.ToString();
}
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
Dim oWeb As SPWeb = SPContext.Current.Web
Try
Dim list As SPList = oWeb.Lists("Projects")
Dim query As New SPQuery()
query.Query = "<Where><Gt><FieldRef Name='ProjectedValue'/>" +
"<Value Type='Number'>5000</Value></Gt></Where>"
Dim listItems As SPListItemCollection = list.GetItems(query)
Dim listItem As SPListItem
Dim sb As StringBuilder = New StringBuilder
' The indenting of the following lines of code has been
' modified for readability. Please modify as
' needed.
For Each listItem In listItems
sb.Append("Item: ")
sb.Append(SPEncode.HtmlEncode(Convert.ToString(oListItem("Title"))))
sb.Append("::Value: ")
sb.Append(SPEncode.HtmlEncode(Convert.ToString(oListItem("Status"))))
sb.Append("::Calculated: ")
sb.Append(SPEncode.HtmlEncode(ConvertToString(oListItem("Cost"))))
sb.Append("<BR>")
Next listItem
Label1.Text = sb.ToString
Finally
siteCollection.Dispose()
End Try
End If
End Sub
For more information, see Lists (How Do I... in Windows SharePoint Services).
Event Handlers (Also Known as Event Receivers)
Windows SharePoint Services allows you to programmatically create, manage, and retrieve information from documents libraries and lists. Additionally, you can create receiver classes that handle both synchronous and asynchronous events. It is possible to hook up and override multiple event handler assemblies from your custom lists, document libraries, sites, and user operations. This gives you the power of SQL triggers on SharePoint lists.
For example, let's say you want to avoid user deletion of items from a custom "Projects" list. To handle this event, you must override the ItemDeleting event of a list definition. Each time a user tries to delete an item, the user should receive a message. The following code example shows how to override the ItemDeleting event handler. This event receiver will prevent attempts at deleting items—even from users that have delete permission on the list.
public override void ItemDeleting(SPItemEventProperties properties)
{
properties.Cancel = true;
properties.ErrorMessage = "Deleting is not supported in this list.";
}
Public Overrides Sub ItemDeleting(ByVal properties As SPItemEventProperties)
properties.Cancel = true
properties.ErrorMessage = "Deleting is not supported in this list."
End Sub
For more information, see Event Fundamentals.
Workflows
Workflows allow you to streamline individual tasks and coordinate business processes. Using ASP.NET, you can build a set of Web forms to submit data and initiate workflows. However, you have to write a lot of business logic code to automate a workflow. Fortunately, SharePoint Products and Technologies offer built-in support for workflow customizations.
Windows SharePoint Services 3.0 provides support to create document-oriented workflow solutions. You can associate workflows to lists, document libraries, or content types. Because Windows SharePoint Services 3.0 workflows are associated to the data that humans manage, it allows you to integrate a human dimension to your workflow solutions. You can define a set of approvers and users who perform the tasks on a workflow instance.
The Microsoft.SharePoint.Workflow namespace provides a set of classes, interfaces, and enumerations that represent workflow functionality encapsulated in Windows SharePoint Services 3.0.
Workflow solutions may or may not have input forms that allow end users to interact with workflows. You can use ASP.NET Web forms to define any of the following kind of workflow forms:
-
Association form. Allows you to define the name of and data associated with the workflow when connecting it to a document library, list, or content type.
-
Initiation form. Allows you to specify information about the specific workflow instance for an item when a workflow instance starts. This form is presented to end-users only when a workflow is started manually.
-
Task forms. Allows you to control the display of tasks associated with a workflow and define special processing when editing a task. This set of forms is implemented with the content type functionality that allows you to display, edit, and customize new forms for any content type.
-
Modification form. Allows you to control the state and flow of a workflow by using custom pages, which can manipulate the data that the workflow is using.
-
Status form. Allows you to define a custom status page to display to the user when the user checks the status of the workflow. This page can reach into other systems to correlate the SharePoint workflow with the data from other systems.
Office SharePoint Server 2007 provides additional enhancements for document-oriented workflows. Some of these capabilities include:
-
Support for using InfoPath forms through InfoPath Forms Services for any association, initiation, task, modification, or status form.
-
Customizable built-in workflows for approval and review.
For more information, see Developer Introduction to Workflows for Windows SharePoint Services 3.0 and SharePoint Server 2007.
To create workflow solutions, you can use Visual Studio 2005, Visual Studio 2008, or Office SharePoint Designer 2007.
Office SharePoint Designer 2007 provides support for simple rules-based workflows. It allows you to define workflows without writing custom code and simplifies the deployment process by automatically storing workflow markup, rules, and supported files in a specific document library. You can associate Office SharePoint Designer 2007 workflows with multiple document libraries or lists.
However, Visual Studio 2005 and Visual Studio 2008 provide a set of custom workflow templates that allow a greater level of customization. Both development environments provide a basic activity library that contains a set of predefined activities you can use to define workflows. You can also create custom activities that you can reuse in different workflow solutions. For example, you can create a custom activity to add workflow steps as tasks in Microsoft Office Outlook 2007. Figure 6 shows SharePoint Sequential Workflow and SharePoint State Machine Workflow templates in Visual Studio 2008.
Figure 6. Workflow templates in Visual Studio 2008
Note: |
|---|
|
Visual Studio developed workflow templates are deployed via Features and solutions. These workflow templates can be reused between libraries in the same site collection, among sites in the same Web application, and even across sites in different SharePoint farms.
|
For more information, see SharePoint Workflow Solutions.
Silverlight in Web Parts
Microsoft Silverlight is a cross-browser, cross-platform, and cross-device plug-in for delivering the next generation of .NET Framework–based media experiences and Rich Internet Applications (RIAs) for the Web. For more information, see ASP.NET Silverlight Overview.
Silverlight offers improved interactive experiences for Web-based applications. For that reason, .NET-technology developers are interested in providing Silverlight features and components for new Web-based solutions. SharePoint developers can also take advantage of Silverlight in their SharePoint-based solutions.
Silverlight UI elements can help you integrate rich interactive functionality in SharePoint sites. You can create Web parts, document libraries, picture libraries, navigation, and custom field types that provide Silverlight support on SharePoint sites.
The Microsoft Silverlight Blueprint for SharePoint provides source code and guidance for developers that describe how to use Silverlight and Microsoft SharePoint Products and Technologies together in business applications and Internet Web sites. This capability enables a fresh look at data exposed through SharePoint Products and Technologies by using the latest graphics capability in Silverlight. Figure 7 shows a Silverlight Picture Viewer sample hosted in an ASP.NET 2.0 Web Part that is running on the SharePoint Platform.
Figure 7. Silverlight picture viewer sample
For more information, see Microsoft Silverlight Blueprint for SharePoint.
Page Branding
Windows SharePoint Services 3.0 and Office SharePoint Server 2007 include a set of built-in templates, master pages, and CSSs that allow you to customize the appearance (look and feel) of SharePoint sites.
The ASP.NET page framework provides a set of features that enable you to create and enhance the look and feel of Web applications. Some of these features include the following:
-
Master pages. Determine overall layout, structure, and interface elements with master pages (described earlier in this article). Use master pages to provide a consistent layout for Web sites you develop.
-
Styles. Define rich design through CSSs and the style property of standard HTML tags, HTML controls, and Web controls.
-
Themes. Define the look and feel of Web pages by using a group of files (CSS and images) that compose a theme.
Because SharePoint Products and Technologies use ASP.NET 2.0 as a platform and framework, you can also modify master pages, CSSs, and images of a SharePoint site for branding purposes.
In Office SharePoint Server 2007, master pages are stored in the Master Page Gallery. Windows SharePoint Services exposes the Master Page Gallery as a document library that stores all existing master page definitions of a site collection. You can explore the contents of the Master Page Gallery and modify the built-in templates to create custom master pages as you need. Figure 8 shows a branded SharePoint site that uses a master page.
Figure 8. Branded SharePoint site
Note: |
|---|
|
The default.master file contains controls such as ASP.NET server and user controls and SharePoint framework controls such as SPWebPartManager, SiteActions, SiteLogoImage, and CSSLink.
|
For more information, see Customizing and Branding Web Content Management-Enabled SharePoint Sites (Part 1 of 3): Understanding Web Content Management and the Default Features.
Page Navigation
ASP.NET 2.0 provides a site navigation model that includes a site navigation API, a set of navigation providers, and server controls that allow you to control site navigation programmatically. The Site Navigation API has a SiteMapProvider class you can use to store your navigational data. You can then author a custom provider that derives from the SiteMapProvider class to retrieve other data stores that use other formats.
Office SharePoint Server 2007 provides the PortalSiteMapProvider class that derives from the ASP.NET SiteMapProvider class. The PortalSiteMapProvider class, in the Microsoft.SharePoint.Publishing namespace, allows you to retrieve site hierarchy data. Therefore, you get enhanced navigation control on SharePoint sites.
ASP.NET also provides a set of navigation controls such as the SiteMapPath, TreeView, and Menu controls. These controls allow you to provide graphical site navigation in your Web sites. In the same way, Office SharePoint Server 2007 uses the Microsoft.SharePoint.WebControls.AspMenu control to provide menu-based navigation. By following the same approach you use for ASP.NET Web sites, you can programmatically customize navigation of SharePoint sites.
Finally, ASP.NET also provides data source controls that allow you to connect navigation controls with the underlying provider of navigation data. Office SharePoint Server 2007 provides the PortalSiteMapDataSource control that lets you link navigation controls to navigation data via the DataSourceID attribute of navigation controls. Therefore, you can use a PortalSiteMapDataSource control in the same way you use a SQLDataSource, an XMLDataSource, an AccessDataSource, or an ObjectDataSource Web server control to bind navigation data to server controls such as a TreeView or Menu control.
Master pages in SharePoint Products and Technologies, such as the default.master page, are used to store page navigation providers and controls. The following sample code shows the partial contents of a default.master page that contains page navigation definitions encapsulated in an asp:ContentPlaceHolder control.
<asp:ContentPlaceHolder ID="PlaceHolderHorizontalNav" runat="server">
<sharepoint:aspmenu
id="TopNavigationMenu"
runat="server"
datasourceid="topSiteMap"
enableviewstate="false"
accesskey="<%$Resources:wss,navigation_accesskey%>"
orientation="Horizontal"
staticdisplaylevels="2"
maximumdynamicdisplaylevels="1"
dynamichorizontaloffset="0"
staticpopoutimageurl="/_layouts/images/menudark.gif"
staticpopoutimagetextformatstring=""
dynamichoverstyle-backcolor="#CBE3F0"
skiplinktext=""
staticsubmenuindent="0"
cssclass="ms-topNavContainer">
<StaticMenuStyle/>
<StaticMenuItemStyle CssClass="ms-topnav" ItemSpacing="0px"/>
<StaticSelectedStyle CssClass="ms-topnavselected" />
<StaticHoverStyle CssClass="ms-topNavHover" />
<DynamicMenuStyle BackColor="#F2F3F4" BorderColor="#A7B4CE"
BorderWidth="1px"/>
<DynamicMenuItemStyle CssClass="ms-topNavFlyOuts"/>
<DynamicHoverStyle CssClass="ms-topNavFlyOutsHover"/>
<DynamicSelectedStyle CssClass="ms-topNavFlyOutsSelected"/>
</sharepoint:aspmenu>
<sharepoint:delegatecontrol runat="server"
controlid="TopNavigationDataSource">
<Template_Controls>
<asp:SiteMapDataSource
ShowStartingNode="False"
SiteMapProvider="SPNavigationProvider"
id="topSiteMap"
runat="server"
StartingNodeUrl="sid:1002"/>
</Template_Controls>
</sharepoint:delegatecontrol>
</asp:ContentPlaceHolder>
For more information, see Customizing and Branding Web Content Management-Enabled SharePoint Sites (Part 2 of 3): Extending WCM.
Web Services
Web services allow your Web-based applications to connect to other software applications over a network, and therefore enable you to build distributed, service-oriented systems. As an ASP.NET developer, you may have already connected your Web-based applications to multiple Web services. If that's the case, you will be pleased to know that both Windows SharePoint Services and Office SharePoint Server offer a wide variety of Web services that you can use to retrieve and configure information from SharePoint sites.
Windows SharePoint Services Web Services
Windows SharePoint Services Web services are part of the Microsoft.SharePoint.SoapServer namespace. These Web services include methods for accessing and customizing SharePoint site content such as lists, site data, forms, meetings, document workspaces, and permissions. Figure 9 shows the various Windows SharePoint Services Web services.
Figure 9. Windows SharePoint Services Web services
To add a reference to a Windows SharePoint Services Web service in Visual Studio, add a Web Reference using the path of the SharePoint site for which the Web service is available. For example, to connect to the meetings Web service, you need to add a reference to the following: http://MyServer/[sites/][MySite/][MySubsite/]_vti_bin/meetings.asmx.
For more information, see Windows SharePoint Services Web Services.
Office SharePoint Server 2007 Web Services
Office SharePoint Server 2007 provides Web services to expose capabilities such as the Business Data Catalog, document management, Enterprise Search, Excel Services, InfoPath Forms Services, and Web content management (WCM). You can use multiple Web services to retrieve information and configure SharePoint sites. The following table lists the most commonly used Office SharePoint Server 2007 Web services.
Table 1. Commonly used Office SharePoint Server Web services
|
Web Service
|
Description
|
Reference
|
|---|
|
Excel Services Web Service
|
Provides a Web services interface to enable applications to access manipulate, and calculate data in workbooks.
|
ExcelService.asmx
|
|
InfoPath Forms Web Service
|
Provides the implementations of features that are used internally by InfoPath Forms Services.
|
FormsService.asmx
|
|
Official File Web Service
|
Provides methods for sending files.
|
officialfile.asmx
|
|
Published Links Web Service
|
Provides a published links interface for remote clients to read and create published links.
|
PublishedLinksService.asmx
|
|
Query Web Service
|
The Query Web service allows you to access Enterprise Search results from client applications and Web applications outside of the context of a SharePoint site.
|
search.asmx
|
|
User Profile Change Web Service
|
Provides a user profile interface for remote clients to read and create user profiles
|
UserProfileChangeService.asmx
|
|
User Profile Web Service
|
Includes methods to manage user profiles
|
UserProfileService.asmx
|
|
Workflow Web Service
|
Provides a workflow interface remote clients can use to perform actions such as getting information about workflow for an item or workflow task, starting a workflow, or getting workflow templates.
|
workflow.asmx
|
You add a reference to an Office SharePoint Server Web service in Visual Studio by adding a Web Reference that uses the path of the SharePoint site for which the Web service is available. For example, to connect to the Search Web service, you need to add a reference to the following: http://MyServer/[sites/][MySite/][MySubsite/]_vti_bin/search.asmx.
For more information, see Class Library and Web Service Reference.
Custom Content Types
As explained earlier in this article, content types are designed to help users organize their SharePoint content in a more meaningful way. A content type is a reusable collection of settings you can apply to a certain category of content, such as documents and folders. For example, you can define a custom purchase order document type. Windows SharePoint Services allows you to define custom columns to track metadata and behaviors such as workflow, forms, event handlers, and information policies that are specific to this document type. Additionally, you want to define a custom contract for external vendors and store it in the same document library. Content types enable you to store multiple types of content in the same document library or list. Content types are independent of a SharePoint list location. After you define a content type, you can use it throughout an entire site collection. Content types let you extend functionality by allowing you to define additional settings, custom workflows, and attributes.
You can create content types by using the UI in Office SharePoint Server 2007, by using the Windows SharePoint Services object model, or via a SharePoint Feature. The Microsoft.SharePoint namespace provides a SPContentType class that represents a site or list content type that you can use to retrieve information and manipulate a content type programmatically. The following code example shows how to add a Status field to an existing "Projects" content type.
SPWeb mySite = SPContext.Current.Web;
SPContentType contentType = mySite.ContentTypes["Projects"];
StringCollection values = new StringCollection();
sc.AddRange(new string[]{ "Not Started","On Track","Completed" });
contentType.Fields.Add("Status",SPFieldType.Choice, false, true, values);
contentType.Update();
Dim mySite As SPWeb = SPContext.Current.Web
Dim contentType As SPContentType = mySite.ContentTypes("Projects")
Dim values As StringCollection = New StringCollection
sc.AddRange(New String() {"Not Started", "On Track", "Completed"})
contentType.Fields.Add("Status", SPFieldType.Choice, false, true, values)
contentType.Update
For more information, see Content Types.
User Management
ASP.NET provides support for role-based authentication. This allows you to programmatically control different access levels for users to Web pages. For example, you can have a Web site that has Web pages that can be seen only by managers, and Web pages that can be seen only by vice presidents. ASP.NET provides a set of different membership and role manager providers that allow you to customize and control authorization in your application.
In the same way, Office SharePoint Server 2007 allows you to define custom user profiles and audiences so you can control authorization to SharePoint sites. In addition, you can use user profiles and audiences to target content and information in content pages. For example, you can show or hide Web Parts in a content page based on audiences. Figure 10 shows how to define target audiences for a Web Part in content pages.
Figure 10. Define target audiences in Web Parts
User Profiles
In Office SharePoint Server 2007, user account property information is stored in a user profile store. Office SharePoint Server 2007 can import user profile information from Active Directory and Lightweight Directory Access Protocol (LDAP) domain controllers. Additionally, Office SharePoint Server 2007 supports the import of user profile information stored in databases or enterprise applications, such as SAP or Siebel, through the Business Data Catalog. You can even schedule incremental or full regular imports to the user profile store. For more information, see Importing User Profiles.
After you define the source and populate the user profile store, you can access and configure user information programmatically by using either the object model classes in the Microsoft.Office.Server namespace, or the Using the User Profile Service Web Service.
Audiences
In Office SharePoint Server 2007, you can define audiences and content targeting based on audience rules, SharePoint groups, and Microsoft Exchange Server distribution list (DL) memberships.
Office SharePoint Server 2007 also provides an Audience object model that allows you to target content programmatically. The Audience object model is implemented in the Audience Object Model Overview namespace.
If you are building Web Part solutions, you can implement the IRuntimeFilter2 interface to control which Web Parts are rendered at run time. The selection of Web Parts is based on a set of arbitrary parameters that are stored in the AuthorizationFilter property of the Web Part base class.
For more information, see Targeting Content Using Audiences.