I recently wanted to display data from a Web Service on a page in SharePoint using XSL. The Web Service was external to SharePoint, which resulted in the Data View web Part being unable to obtain a valid result required to allow the XSL template to be built using features of SharePoint Designer. A separate issue was that the method used to query the web service hosted on my external server consumed resources on the external application and took around 5 seconds to receive a response from the query. Using a Data View web part connected directly to the Web Service to display the result would require that the data is obtained every time the page loads, impacting on server performance.
Saturday, July 7, 2012
Web Service Response Cache using VB Script (VBS) and SharePoint
Labels:
Data View,
Frontpage RPC,
SOAP,
VBScript,
Web Services,
XML,
XSL
Sunday, November 13, 2011
Extend SharePoint 2010 User Interface for Lists - Ribbon, Menus & Toolbars
In my previous post, I demonstrated how to customise the User Interface for Libraries in SharePoint 2010 by adding links / custom actions in existing Menus, the Ribbon and Document Library Settings pages.
This post follows on by demonstrating how to customise the interface for different types of lists built into SharePoint 2010 by adding new custom actions to the menus and existing groups in the Ribbon.
Contents:
1. Extending the User Interface for Items
This post follows on by demonstrating how to customise the interface for different types of lists built into SharePoint 2010 by adding new custom actions to the menus and existing groups in the Ribbon.
Contents:
1. Extending the User Interface for Items
- 1.1 Add a custom link to the List Item Menu (ECB / LIM) for an Announcements list
- 1.2 Add a Custom Action to the “Manage” group in the Events tab of a Calendar / Events List
- 2.1 Add a Link to the New menu for a Task List
- 2.2 Add a Custom Control to the existing New Group in the Items tab on the Ribbon for a Task List
- 3.1 Add a Custom Action to the Actions Menu and “Custom Actions” tab for a Links list in SharePoint 2010
- 3.2 Add A Custom Link to the existing “Share & Track” group on the List tab of the Ribbon for a Links List
- 3.3 Add A Custom Link to the Manage Views Group on the List tab of the Ribbon
- 4.1 Add a custom link to the Settings menu for a Calendar list in SharePoint 2010
- 4.2 Add a Custom Action to the Settings Group on the Ribbon for a Calendar in SharePoint 2010
- 4.3 Add a Custom Button / Link to the “Customize List” group in the Calendar tab on the Ribbon
- 5.1 Add a custom link to an existing group/heading on the Settings page for a Discussion Board in SharePoint 2010
Labels:
Custom Actions,
List Templates,
Ribbon,
Ribbon Customisation,
UI,
User Interface
Monday, November 7, 2011
SharePoint 2010: Extend the Document Library Menus, Ribbon and Settings Interface
In this tutorial I demonstrate how to customise the interface for Document Libraries in SharePoint 2010 using Custom Actions. I explain how to target specific types of Libraries built-in to SharePoint, and how to include additional links/actions to menus, the Server Ribbon and settings pages associated with Document Libraries.
This tutorial covers the following:
RegistrationId’s for Document Library types in SharePoint 2010
A list of Registration ID used to target specific types of Document Libraries built-in to SharePoint 2010 when adding new links / controls to the built in Interface.
1. Customise the Interface for the New Menu and Ribbon Group
- 1.1 Add a link to the New Menu for a Document Library in SharePoint 2010
- 1.2 Add a control to the “New” Group on the Ribbon for a Document Library in SharePoint 2010
2. Customise the Interface for the Actions Menu and Library Action Groups on the Ribbon
- 2.1 Add a link to the Actions menu for a Document Library in SharePoint 2010
- 2.2 Add a Control to the View Format Group on the Ribbon for a Document Library
- 2.3 Add a Control to the “Connect & Export” group on the Ribbon for a Document Library (Document Library Actions)
- 2.4 Customise the Share & Track Group
3. Customise the Settings Menu and Library Management / Settings Groups on the Ribbon
- 3.1 Add a link to the Settings Menu for a Document Library in SharePoint 2010
- 3.2 Add A Control to the Customise Library Group on the Ribbon for a Document Library
- 3.3 Add A Control to the Settings Group on the Ribbon for a Document Library
4. Item Level Customisations to the Interface and Ribbon
- 4.1 Add a link to the Edit Control Block (item drop-down) menu for a Document
- 4.2 Add a Control to the “Manage” group on the Ribbon for Documents
- 4.3 Add a Control to the “Share & Track” (Share) Group on the Ribbon for a Document Library
- 4.4 Add a Control to the “Workflows” Group on the Ribbon for a Document Library
5. Customise the Document Library Settings Page
- 5.1 Add a link to the Settings Page for a Document Library in SharePoint 2010
Wednesday, October 26, 2011
Tutorial: Add Custom List actions using SharePoint Designer 2010
One of the new features of SharePoint 2010 is the ability to easily add Custom Actions buttons to the Ribbon, List item menu and the built-in forms (Display, Edit and New). This can be done with SharePoint Designer 2010 and the “Custom Actions” functionality. In this tutorial I explain how to use this feature to add custom action buttons to various parts of the UI for lists and libraries in SharePoint 2010.
Monday, October 24, 2011
Add Custom Links to the SharePoint 2010 UI as a Feature with or without using Visual Studio
In this article, I demonstrate the process of adding a custom link and group to the UI in SharePoint as a Site Feature without using Visual Studio, as well as using Visual Studio.
In some cases you may not have Visual Studio installed on a Server running SharePoint, or may just want to quickly add a custom link in the interface such as on the Site Settings page, or the Actions or Settings menu for a Document Library or List. In other cases you may have a project in Visual Studio containing new functionality to be deployed to a SharePoint environment, that needs to be accessed through adding custom links to the UI. It makes sense to deploy the custom links as part of the solution feature, so I also explain how to achieve this from a Visual Studio Project.
In some cases you may not have Visual Studio installed on a Server running SharePoint, or may just want to quickly add a custom link in the interface such as on the Site Settings page, or the Actions or Settings menu for a Document Library or List. In other cases you may have a project in Visual Studio containing new functionality to be deployed to a SharePoint environment, that needs to be accessed through adding custom links to the UI. It makes sense to deploy the custom links as part of the solution feature, so I also explain how to achieve this from a Visual Studio Project.
Labels:
Custom Actions,
Features,
PowerShell,
STSADM,
User Interface,
Visual Studio 2010
Apply Permissions to Custom UI Links / Actions in SharePoint Menus and Settings Pages
This post explains how to incorporate permissions into custom links and actions added to the UI on menus, toolbars and default layout pages such as the Site Settings page in SharePoint 2010.
Examples included in the post are:
Examples included in the post are:
- Restricting custom links on list settings pages to only site collection administrators
- Adding custom actions to the Document Library dropdown menu (ECB - Edit Control Block) that are displayed only to users with edit permissions on the document.
- Displaying a link on the Site Actions menu only to users with access to manage permissions for the current site.
- Displaying a custom link on the List Actions menu for users with access to manage the list.
- Display a link on the Site Settings page of a site to users with access to add and customise pages on the site, as well as apply themes and stylesheets to the site (Site Designers).
Saturday, October 22, 2011
SharePoint Application Page Security
This article covers information relating to security for Application pages and page components in SharePoint:
- Selecting the correct base class to inherit from when developing Application Pages in SharePoint
- Securing Application pages with user permissions
- Specifying when the CheckRights method is called to determine if a user has access to the page.
- Programmatically check if the user has permission to access the page
- Code Access Security (CAS) Policy for SharePoint Components
Tuesday, October 18, 2011
SPBasePermissions Usage With (Programmatic) and Without Code
In this post, I list some of the properties and methods that return a SPBasePermissions enum, and some methods that take SPBasePermissions as a parameter when checking if a user has certain rights on an object in SharePoint. Later in the post I also explain how the permission masks with SPBasePermissions can be used to customise (show / hide ) content and custom UI actions / links without using code.
The following are some of the more common components in SharePoint that can be used to get or set permissions, or check if certain permissions are effective for a user on the object.
Get or set the Base Permissions for a Role Definition in a Web
SPWeb.RoleDefinitions.BasePermissions
Get the current or specified user’s effective SPBasePermissions on an object (SPWeb, SPList, SPListItem, etc.) Username passed as String to GetUserEffectivePermissions():
SPSite
SPSite.EffectiveBasePermissions
SPSite.GetEffectiveRightsForAcl(SPReusableAcl)
SPWeb
SPWeb.EffectiveBasePermissions
SPWeb.GetUserEffectivePermissions(String)
SPList
SPList.EffectiveBasePermissions
SPList.EffectiveFolderPermissions
SPList.GetUserEffectivePermissions(String)
SPFolder
SPFolder.EffectiveRawPermissions
SPFile
SPFile.EffectiveRawPermissions
SPListItem
SPListItem.EffectiveBasePermissions
SPListItem.GetUserEffectivePermissions(String)
Check if the current or specified user has the specified permissions and throws UnauthorizedAccessException if not:
SPSite.CheckForPermissions(SPReusableAcl, SPBasePermissions)
SPWeb.CheckPermissions(SPBasePermissions)
SPList.CheckPermissions(SPBasePermissions)
SPListItem.CheckPermissions(SPBasePermissions)
Returns true/false indicating if the user has the specified permission(s)
SPSite
SPSite.DoesUserHavePermissions(SPReusableAcl, SPBasePermissions)
SPSite.DoesUserHavePermissions(SPReusableAcl, SPBasePermissions, SPWeb)
SPWeb
SPWeb.DoesUserHavePermissions(SPBasePermissions)
SPWeb.DoesUserHavePermissions(String, SPBasePermissions)
SPList
SPList.DoesUserHavePermissions(SPBasePermissions)
SPList.DoesUserHavePermissions(SPUser, SPBasePermissions)
SPListItem
SPListItem.DoesUserHavePermissions(SPBasePermissions)
SPListItem.DoesUserHavePermissions(SPUser, SPBasePermissions)
Layout Page Base - Permissions required to access a LayoutPageBase
LayoutsPageBase.RightsRequired
LayoutsPageBase.DefaultLayoutsRights
Trimmed Content on a Page (Get or set permissions)
SPSecurityTrimmedControl.Permissions
Base permissions associated with a SPPermission object
SPPermission.BasePermissions
Get base permissions required to use a ConsoleAction object or ConsoleNode
ConsoleAction.UserRights
ConsoleNode.UserRights
Get permissions required to see the developer dashboard
SPDeveloperDashboardSettings.RequiredPermissions
Get or set the permissions for a web application
SPWebApplication.RightsMask
SPSite.ApplicationRightsMask
Permissions required to access a Mobile Page
SPMobilePage.RightsRequired
Toolbar Menu Button
ToolBarMenuButton.CallbackVisibilityPermission
Others:
SPSecurableObject.GetUserEffectivePermissions(String UserName)
SPRibbon.Permissions
MenuItemTemplate.Permissions
SPUserCustomAction.Rights
The SPBasePermissions Enum contains a number of built-in permissions that can be used in a number of ways, including showing or hiding content for a user based on their access level to a site, list or item, restricting custom links and actions added to the UI, securing application pages and much more. When creating a .aspx page or Master Page in SharePoint SPSecurityTrimmedControl class has a PermissionsString parameter that accepts a comma separated list of SPBasePermissions which a user must have for the child content or controls to be displayed to the user.
SharePoint: Show or Hide Content based on Permissions provides an example usage of the SPSecurityTrimmedControl class with various permissions from the SPBasePermissions enum to include content on a Master Page that is visible to users with full access to a site, or a user with access to manage lists on the site. The example includes a “View All Site Content: link as content near the top of the page, which is visible only to users with the matching permissions. References to the relevant documentation
For additional examples for a number of specific scenarios, the article Permission Based Content in SharePoint (With Examples) provides configuration of the SPSecurityTrimmedControl class and various SPBasePermissions to achieve each. Some of the examples include displaying content or controls only to users with full access to a site, showing content for users with access to manage permissions on a site and displaying content to uses with add, edit and modify permissions on list items in a list. The article also demonstrates usage of the SPSecurityTrimmedControl class and the AuthenticationRestrictions attribute to show or hide content to users who are authenticated or anonymous.
SPBasePermissions are also used when adding custom links and actions to the User Interface in SharePoint such as the Site or List Settings page, the Actions or Settings menu on lists and libraries and the list item dropdown (ECB Edit Control Block) menu. Associating one or more of the built-in permissions with these custom actions will mean that a user much have each of the permissions on the item, list or site for the Custom action to be displayed.
Programmatic uses of SPBasePermissions to check for or set permissions on various objects in SharePoint
The following are some of the more common components in SharePoint that can be used to get or set permissions, or check if certain permissions are effective for a user on the object.
Get or set the Base Permissions for a Role Definition in a Web
SPWeb.RoleDefinitions.BasePermissions
Get the current or specified user’s effective SPBasePermissions on an object (SPWeb, SPList, SPListItem, etc.) Username passed as String to GetUserEffectivePermissions():
SPSite
SPSite.EffectiveBasePermissions
SPSite.GetEffectiveRightsForAcl(SPReusableAcl)
SPWeb
SPWeb.EffectiveBasePermissions
SPWeb.GetUserEffectivePermissions(String)
SPList
SPList.EffectiveBasePermissions
SPList.EffectiveFolderPermissions
SPList.GetUserEffectivePermissions(String)
SPFolder
SPFolder.EffectiveRawPermissions
SPFile
SPFile.EffectiveRawPermissions
SPListItem
SPListItem.EffectiveBasePermissions
SPListItem.GetUserEffectivePermissions(String)
Check if the current or specified user has the specified permissions and throws UnauthorizedAccessException if not:
SPSite.CheckForPermissions(SPReusableAcl, SPBasePermissions)
SPWeb.CheckPermissions(SPBasePermissions)
SPList.CheckPermissions(SPBasePermissions)
SPListItem.CheckPermissions(SPBasePermissions)
Returns true/false indicating if the user has the specified permission(s)
SPSite
SPSite.DoesUserHavePermissions(SPReusableAcl, SPBasePermissions)
SPSite.DoesUserHavePermissions(SPReusableAcl, SPBasePermissions, SPWeb)
SPWeb
SPWeb.DoesUserHavePermissions(SPBasePermissions)
SPWeb.DoesUserHavePermissions(String, SPBasePermissions)
SPList
SPList.DoesUserHavePermissions(SPBasePermissions)
SPList.DoesUserHavePermissions(SPUser, SPBasePermissions)
SPListItem
SPListItem.DoesUserHavePermissions(SPBasePermissions)
SPListItem.DoesUserHavePermissions(SPUser, SPBasePermissions)
Layout Page Base - Permissions required to access a LayoutPageBase
LayoutsPageBase.RightsRequired
LayoutsPageBase.DefaultLayoutsRights
Trimmed Content on a Page (Get or set permissions)
SPSecurityTrimmedControl.Permissions
Base permissions associated with a SPPermission object
SPPermission.BasePermissions
Get base permissions required to use a ConsoleAction object or ConsoleNode
ConsoleAction.UserRights
ConsoleNode.UserRights
Get permissions required to see the developer dashboard
SPDeveloperDashboardSettings.RequiredPermissions
Get or set the permissions for a web application
SPWebApplication.RightsMask
SPSite.ApplicationRightsMask
Permissions required to access a Mobile Page
SPMobilePage.RightsRequired
Toolbar Menu Button
ToolBarMenuButton.CallbackVisibilityPermission
Others:
SPSecurableObject.GetUserEffectivePermissions(String UserName)
SPRibbon.Permissions
MenuItemTemplate.Permissions
SPUserCustomAction.Rights
Show / Hide content in SharePoint based on the built-in permissions in SharePoint without code.
The SPBasePermissions Enum contains a number of built-in permissions that can be used in a number of ways, including showing or hiding content for a user based on their access level to a site, list or item, restricting custom links and actions added to the UI, securing application pages and much more. When creating a .aspx page or Master Page in SharePoint SPSecurityTrimmedControl class has a PermissionsString parameter that accepts a comma separated list of SPBasePermissions which a user must have for the child content or controls to be displayed to the user.
SharePoint: Show or Hide Content based on Permissions provides an example usage of the SPSecurityTrimmedControl class with various permissions from the SPBasePermissions enum to include content on a Master Page that is visible to users with full access to a site, or a user with access to manage lists on the site. The example includes a “View All Site Content: link as content near the top of the page, which is visible only to users with the matching permissions. References to the relevant documentation
For additional examples for a number of specific scenarios, the article Permission Based Content in SharePoint (With Examples) provides configuration of the SPSecurityTrimmedControl class and various SPBasePermissions to achieve each. Some of the examples include displaying content or controls only to users with full access to a site, showing content for users with access to manage permissions on a site and displaying content to uses with add, edit and modify permissions on list items in a list. The article also demonstrates usage of the SPSecurityTrimmedControl class and the AuthenticationRestrictions attribute to show or hide content to users who are authenticated or anonymous.
SPBasePermissions are also used when adding custom links and actions to the User Interface in SharePoint such as the Site or List Settings page, the Actions or Settings menu on lists and libraries and the list item dropdown (ECB Edit Control Block) menu. Associating one or more of the built-in permissions with these custom actions will mean that a user much have each of the permissions on the item, list or site for the Custom action to be displayed.
Tuesday, October 11, 2011
Permission Based Content in SharePoint (With Examples)
The examples in this tutorial demonstrate how to restrict certain content or controls on a page in SharePoint to specific users based on their permissions. It can be applied to a Master Page, or directly to a .aspx page in SharePoint using SharePoint Designer. Many options are available to configure exactly how and when the content should be displayed using the base permissions available in SharePoint with the SPSecurityTrimmedControl class.
The complete list of base permissions that can be used with the class can be viewed on this page: SPBasePermissions. It is also possible to show or hide content based on user authentication using the AuthenticationRestrictions property of the class, which may be useful if you want to display a different set of links depending on if a user has been authenticated or is anonymous.
Below are some examples of base permissions that are more likely to be used to restrict content to specific users with the associated permission.
Show content to only a user with full permissions on the site:
<SharePoint:SPSecurityTrimmedControl
ID="ShowContent1"
PermissionsString="ManageWeb"
runat="server">
ASP Controls or HTML included here will be visible only to users with full permission on the site.
</SharePoint:SPSecurityTrimmedControl>
Show content to only users who can manage lists
<SharePoint:SPSecurityTrimmedControl
ID="ShowContent2"
PermissionsString="ManageLists"
runat="server">
ASP Users Controls or HTML included here will be visible only to users who have the Manage Lists permission.
</SharePoint:SPSecurityTrimmedControl>
Show Content to users with access to manage permissions
<SharePoint:SPSecurityTrimmedControl
ID="ShowContent3"
PermissionsString="ManagePermissions"
runat="server">
ASP Users Controls or HTML included here will be visible only to users who can manage permissions.
</SharePoint:SPSecurityTrimmedControl>
Show Content to users who can Add, Edit or Delete List Items in the Current List
Multiple permission levels are separated by a comma. To allow the content to be displayed if a user has any one of the listed base permissions, the PermissionMode property should be included with the mode as “Any” (used in example below). The user must have all permissions listed if PermissionMode=”All” or is not specified. The Context is also set to restrict the permission mask to the current list (PermissionContext=”CurrentList”).
<SharePoint:SPSecurityTrimmedControl
ID="ShowContent4"
PermissionsString="AddListItems, EditListItems, DeleteListItems"
PermissionMode=”Any”
PermissionContext=”CurrentList”
runat="server">
Content here will be displayed if a user has access to Add Edit or Delete list items.
</SharePoint:SPSecurityTrimmedControl>
Show a link to Anonymous (not authenticated) users only
<SharePoint:SPSecurityTrimmedControl
ID="ShowContent5"
AuthenticationRestrictions=”AnonymousUsersOnly”
runat="server">
<a href=”/” >Link displayed for Anonymous Users Only</a>
</SharePoint:SPSecurityTrimmedControl>
Show a link to Authenticated users only
<SharePoint:SPSecurityTrimmedControl
ID="ShowContent6"
AuthenticationRestrictions=”AuthenticatedUsersOnly”
runat="server">
<a href=”/” >Link displayed for Authenticated Users Only</a>
</SharePoint:SPSecurityTrimmedControl>
Some of the properties used in the examples above to customise use of the SPSecurityTrimmedControl class when restricting content for specific users are below:
Related:
SharePoint: Show or Hide Content based on Permissions - This article demonstrates how to show a “View All Site Content” link to users with full permission on a site, or with access to Manage Lists on a site using SPSecurityTrimmedControl. It is placed in a Master Page using SharePoint Designer.
The complete list of base permissions that can be used with the class can be viewed on this page: SPBasePermissions. It is also possible to show or hide content based on user authentication using the AuthenticationRestrictions property of the class, which may be useful if you want to display a different set of links depending on if a user has been authenticated or is anonymous.
Below are some examples of base permissions that are more likely to be used to restrict content to specific users with the associated permission.
Show content to only a user with full permissions on the site:
<SharePoint:SPSecurityTrimmedControl
ID="ShowContent1"
PermissionsString="ManageWeb"
runat="server">
ASP Controls or HTML included here will be visible only to users with full permission on the site.
</SharePoint:SPSecurityTrimmedControl>
Show content to only users who can manage lists
<SharePoint:SPSecurityTrimmedControl
ID="ShowContent2"
PermissionsString="ManageLists"
runat="server">
ASP Users Controls or HTML included here will be visible only to users who have the Manage Lists permission.
</SharePoint:SPSecurityTrimmedControl>
Show Content to users with access to manage permissions
<SharePoint:SPSecurityTrimmedControl
ID="ShowContent3"
PermissionsString="ManagePermissions"
runat="server">
ASP Users Controls or HTML included here will be visible only to users who can manage permissions.
</SharePoint:SPSecurityTrimmedControl>
Show Content to users who can Add, Edit or Delete List Items in the Current List
Multiple permission levels are separated by a comma. To allow the content to be displayed if a user has any one of the listed base permissions, the PermissionMode property should be included with the mode as “Any” (used in example below). The user must have all permissions listed if PermissionMode=”All” or is not specified. The Context is also set to restrict the permission mask to the current list (PermissionContext=”CurrentList”).
<SharePoint:SPSecurityTrimmedControl
ID="ShowContent4"
PermissionsString="AddListItems, EditListItems, DeleteListItems"
PermissionMode=”Any”
PermissionContext=”CurrentList”
runat="server">
Content here will be displayed if a user has access to Add Edit or Delete list items.
</SharePoint:SPSecurityTrimmedControl>
Show a link to Anonymous (not authenticated) users only
<SharePoint:SPSecurityTrimmedControl
ID="ShowContent5"
AuthenticationRestrictions=”AnonymousUsersOnly”
runat="server">
<a href=”/” >Link displayed for Anonymous Users Only</a>
</SharePoint:SPSecurityTrimmedControl>
Show a link to Authenticated users only
<SharePoint:SPSecurityTrimmedControl
ID="ShowContent6"
AuthenticationRestrictions=”AuthenticatedUsersOnly”
runat="server">
<a href=”/” >Link displayed for Authenticated Users Only</a>
</SharePoint:SPSecurityTrimmedControl>
Some of the properties used in the examples above to customise use of the SPSecurityTrimmedControl class when restricting content for specific users are below:
- PermissionsString - A comma separated list of the base permissions that a user requires for the content to be displayed.
- AuthenticationRestrictions - Displays content based on the authentication status.
- PermissionContext - Sets the context of the permission mask (CurrentFolder, CurrentItem, CurrentList, CurrentSite, RootSite)
- PermissionMode - When multiple base permissions are provided, this property is used to specifies if all of the permissions are required, or any one similar to the use of “&&” (AND) or “||” (OR).
- Full list of SPSecurityTrimmedControl Members.
Related:
SharePoint: Show or Hide Content based on Permissions - This article demonstrates how to show a “View All Site Content” link to users with full permission on a site, or with access to Manage Lists on a site using SPSecurityTrimmedControl. It is placed in a Master Page using SharePoint Designer.
SharePoint 2010: Add User Control to Master Page Using SharePoint Designer 2010
In this article I explain the steps to include a custom User Control in a Master Page in SharePoint 2010 using SharePoint Designer.
In my case, the example User Control I am adding to the Master Page in this tutorial is in the following location which would vary depending on the name and of the Control and the folder it is saved in: “~/_controltemplates/SP2010_UserControl_Example/DynamicSiteTitle.ascx file”
SharePoint Designer 2010 Master Page User Control
Using SharePoint Designer 2010, open the Site and Master Page Library where the Master Page will be stored containing the User Control. In this example, I am creating a copy of the default v4.master used in SharePoint 2010 in the root site Master Page Library and calling it v4b.master.

Open the Master Page you wish to modify by right clicking the and selecting the “Edit File in Advanced Mode” option.
Close to the top of the markup below the existing @Register / @Import tags, add the following line to register the User Control for use in the page. Change the reference to the User Control file (.ascx) to point to your User Control if required:
<%@ Register TagPrefix="custom" TagName="DynamicTitle" src="~/_controltemplates/SP2010_UserControl_Example/DynamicSiteTitle.ascx" %>

Now that the User Control is registered, it can be included in the page by adding an element with the tag prefix and tag name specified when registering the control. As the example User Control displays a dynamic title the tag and prefix have been named to suit, but can be something else if required. The element in this case will look like:
<custom:DynamicTitle id="DynamicTitle1" runat="server"/>
The value of the id attribute can also vary, which should be unique for each instance that the control is included on the page if more than once.
I have added the control to the Site Name placeholder (PlaceHolderSiteName) replacing the existing Property used to display only the title of the current site, as the custom control performs a similar function.
The resulting code looks like:
<h1 name="onetidProjectPropertyTitle">

Save the Master Page, and enable it if required on a SharePoint Site.
The Custom Control should be displayed where you placed it on the Master Page. In this case, the Site title (Team Site), List/Library (Site Pages) and page title (Home) are displayed in the banner of the site.

For assistance with creating a User Control, please see the following tutorial which contains instruction on how to create the example User Control used in this article that displays a dynamic title of the current site, list and page / list item if applicable for demonstration purposes:
Developing a custom User Control for SharePoint 2010
The tutorial covers building a basic User Control from scratch using Visual Studio, and also includes instructions to include the control on an Application page or Master Page. A User Control can be add directly to any .aspx page in SharePoint as well by following the same steps described in this tutorial.
It is also possible to complete these steps in a Master Page included in a solution developed using Visual Studio 2010, which can then be activated on specific sites as a feature, but is not covered in this article. See this article by Mirjam: Deploying a custom master page in SharePoint 2010 for instructions on how to add a Master Page to a Feature using Visual Studio, which also include an event receiver to use the new Master Page when the Feature is activated on a SharePoint site.
Related:
In my case, the example User Control I am adding to the Master Page in this tutorial is in the following location which would vary depending on the name and of the Control and the folder it is saved in: “~/_controltemplates/SP2010_UserControl_Example/DynamicSiteTitle.ascx file”
SharePoint Designer 2010 Master Page User Control
Using SharePoint Designer 2010, open the Site and Master Page Library where the Master Page will be stored containing the User Control. In this example, I am creating a copy of the default v4.master used in SharePoint 2010 in the root site Master Page Library and calling it v4b.master.

Open the Master Page you wish to modify by right clicking the and selecting the “Edit File in Advanced Mode” option.
Close to the top of the markup below the existing @Register / @Import tags, add the following line to register the User Control for use in the page. Change the reference to the User Control file (.ascx) to point to your User Control if required:
<%@ Register TagPrefix="custom" TagName="DynamicTitle" src="~/_controltemplates/SP2010_UserControl_Example/DynamicSiteTitle.ascx" %>

Now that the User Control is registered, it can be included in the page by adding an element with the tag prefix and tag name specified when registering the control. As the example User Control displays a dynamic title the tag and prefix have been named to suit, but can be something else if required. The element in this case will look like:
<custom:DynamicTitle id="DynamicTitle1" runat="server"/>
The value of the id attribute can also vary, which should be unique for each instance that the control is included on the page if more than once.
I have added the control to the Site Name placeholder (PlaceHolderSiteName) replacing the existing Property used to display only the title of the current site, as the custom control performs a similar function.
The resulting code looks like:
<h1 name="onetidProjectPropertyTitle">
<asp:ContentPlaceHolder id="PlaceHolderSiteName" runat="server">
<custom:DynamicTitle id="DynamicTitle1" runat="server"/>
</asp:ContentPlaceHolder>
</h1>
Save the Master Page, and enable it if required on a SharePoint Site.
The Custom Control should be displayed where you placed it on the Master Page. In this case, the Site title (Team Site), List/Library (Site Pages) and page title (Home) are displayed in the banner of the site.

For assistance with creating a User Control, please see the following tutorial which contains instruction on how to create the example User Control used in this article that displays a dynamic title of the current site, list and page / list item if applicable for demonstration purposes:
Developing a custom User Control for SharePoint 2010
The tutorial covers building a basic User Control from scratch using Visual Studio, and also includes instructions to include the control on an Application page or Master Page. A User Control can be add directly to any .aspx page in SharePoint as well by following the same steps described in this tutorial.
It is also possible to complete these steps in a Master Page included in a solution developed using Visual Studio 2010, which can then be activated on specific sites as a feature, but is not covered in this article. See this article by Mirjam: Deploying a custom master page in SharePoint 2010 for instructions on how to add a Master Page to a Feature using Visual Studio, which also include an event receiver to use the new Master Page when the Feature is activated on a SharePoint site.
Related:
- SharePoint Master Page: Include Title of a Site as a link to the Site’s Homepage
Add the title of the current site as a link to the homepage using the "Title" Project Property and ~site token to construct the url to the homepage of the current site.
Subscribe to:
Comments (Atom)