Registering and Importing Namespaces

Applies to: SharePoint Foundation 2010

Use processing instructions to register namespaces, assemblies, and other properties of Microsoft SharePoint Foundation.

For Microsoft ASP.NET pages, use instructions such as the following at the beginning of the code, which register the Microsoft.SharePoint.WebControls, Microsoft.SharePoint.Utilities, Microsoft.SharePoint, and Microsoft.SharePoint.WebPartPages namespaces.

<%@ Register Tagprefix="SharePoint" 
   Assembly="Microsoft.SharePoint, Version=, Culture=neutral, 
   PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" 
   Assembly="Microsoft.SharePoint, Version=, Culture=neutral, 
   PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" 
   Assembly="Microsoft.SharePoint, Version=, Culture=neutral, 
   PublicKeyToken=71e9bce111e9429c" %>

You can obtain the PublicKeyToken value for the current SharePoint Foundation deployment from the default.aspx file that is located in Local_Drive:\Program Files\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\SiteTemplates\sts, or from information provided for the Microsoft.SharePoint assembly at Local_Drive:\%Windir%\assembly in Windows Explorer.

In code-behind files or console applications, import namespaces in through the using directive, as follows.

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

In Microsoft Visual Basic, use the Imports statement to import namespaces, as follows.

Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.WebControls
Imports Microsoft.SharePoint.WebPartPages

See Also


Getting References to Sites, Web Applications, and Other Key Objects

Working with List Objects and Collections

Other Resources

Basic Object Model Tasks in SharePoint 2010