Wednesday, October 13, 2010

Creating Custom Menu with Sub-Menus under Site Actions in SharePoint

We can add custom menu in site actions with our most accessed URL's like "Quota Increase", "Owner change", etc. like the below screen.

But, Why we need to do this?

  1. Well, It's a good user friendly addition, they don't need to search for a link to raise a quota increase or ownership change or etc.
  2. Security trimming - This will avoid incorrect persons raising the request and rejections.
  3. Mistyped URLs – This will avoid  wrong URL's being entered.  On clicking the link, we can direct them to the request form with auto filled URL's of the site.
Creating custom menu with sub menus under site actions

Here is the code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint;

namespace Crescent.SharePointSupport
{
public class SiteActionsMenu : WebControl{
protected override void CreateChildControls()
{
SPContext.Current.Site.CatchAccessDeniedException = false;
base.CreateChildControls();
try{
SPContext.Current.Web.CheckPermissions(SPBasePermissions.ManageSubwebs);
//MenuItemTemplate siteCollSettings =
//GetNewItemTemplate("Top Level Site Settings", "/_layouts/settings.aspx", "/_layouts/images/crtsite.gif", "Manage site settings for top level site.");
//siteCollSettings.Sequence = 399;
//this.Controls.Add(siteCollSettings);
}
catch (UnauthorizedAccessException)
{
// Do nothing}
AddSharePointSupportMenus();
}


private void AddSharePointSupportMenus()
{
try{
SPContext.Current.Web.CheckPermissions(SPBasePermissions.ManagePermissions);
}
catch (UnauthorizedAccessException)
{
return;
}

SubMenuTemplate userAndPermissions = GetNewMenuTemplate("SmartTools.EnhancedSiteActions.UserAndPermissions", "SharePoint Support", "Access SharePoint Support Links.", "/_layouts/images/menuprofile.gif", 402);

string url = string.Format("{0}/_layouts/people.aspx", SPContext.Current.Web.Url);
MenuItemTemplate peopleAndGroups = GetNewItemTemplate("Quota Increase", url, "/_layouts/images/PPEOPLE.GIF", "Raise a Request for increasing the site quota.");
userAndPermissions.Controls.Add(peopleAndGroups);

url = string.Format("{0}/_layouts/user.aspx", SPContext.Current.Web.Url);
MenuItemTemplate advPerm =
GetNewItemTemplate("Ownership Change", url, "/_layouts/images/menupersonalize.gif", "Raise a request to change the site owners.");
userAndPermissions.Controls.Add(advPerm);


url = string.Format("{0}/_layouts/user.aspx", SPContext.Current.Web.Url);
MenuItemTemplate Deletesite = GetNewItemTemplate("Request to delete Site", url, "/_layouts/images/manageuser.gif", "Raise a request to delete the current site.");
userAndPermissions.Controls.Add(Deletesite);

url = string.Format("{0}/_layouts/user.aspx", SPContext.Current.Web.Url);
MenuItemTemplate ChangeURL =GetNewItemTemplate("Request to change Site URL", url, "/_layouts/images/LISTSET.GIF", "Raise a request to change the current site's URL.");
userAndPermissions.Controls.Add(ChangeURL);

url = string.Format("{0}/_layouts/user.aspx", SPContext.Current.Web.Url);
MenuItemTemplate Genquery =GetNewItemTemplate("General Query to Support", url, "/_layouts/images/menuprofile.gif", "Send a question to SharePoint Support.");
userAndPermissions.Controls.Add(Genquery);

url = string.Format("{0}/_layouts/user.aspx", SPContext.Current.Web.Url);
MenuItemTemplate FAQLinks =GetNewItemTemplate("Frequently Asked Questions(FAQ)", url, "/_layouts/images/NEWSPG.GIF", "Access Frequently asked questions section");
userAndPermissions.Controls.Add(FAQLinks);

url = string.Format("{0}/_layouts/user.aspx", SPContext.Current.Web.Url);
MenuItemTemplate Learning =
GetNewItemTemplate("SharePoint Learning", url, "/_layouts/images/Home.gif", "Access SharePoint Learning section");
userAndPermissions.Controls.Add(Learning);
 

this.Controls.Add(userAndPermissions);
}

private static MenuItemTemplate GetNewItemTemplate(string text, string url, string imageUrl, string description)
{
MenuItemTemplate item = new MenuItemTemplate();
item.Text = text;
item.ClientOnClickNavigateUrl = url;

item.ImageUrl = imageUrl;
item.Description = description;
return item;
}

private static SubMenuTemplate GetNewMenuTemplate(string id, string text, string description, string imageUrl, int sequence)
{
SubMenuTemplate menuTemplate = new SubMenuTemplate();
menuTemplate.Text = text;
menuTemplate.Description = description;
menuTemplate.ID = id;
menuTemplate.ImageUrl = imageUrl;
menuTemplate.Sequence = sequence;
return menuTemplate;
}
}

Don't forget to add a safe control entry.



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...