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"
Namespace="Microsoft.SharePoint.WebControls"
Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities"
Namespace="Microsoft.SharePoint.Utilities"
Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages"
Namespace="Microsoft.SharePoint.WebPartPages"
Assembly="Microsoft.SharePoint, Version=14.0.0.0, 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
Concepts
Getting References to Sites, Web Applications, and Other Key Objects
Working with List Objects and Collections