Thursday, February 24, 2011

How To Hide/Remove the View All Site Content link in SharePoint

Summary
This article covers how to hide (remove) the View All Site Content link and/or the Recycle Bin link from the quick launch navigation without having to customize the master page.  Additionally, I cover how I accomplished along with other options, all using the standard functionality provided in Windows SharePoint Services 3.0.
Important: This solution is not an answer for security.  The user will still have access to the View All Site Content page.  The View All Site Content link is simply removed or hidden from the page.
Applies To
  • Windows SharePoint Services 3.0
  • Microsoft Office SharePoint Server 2007
  • Sorry, but this does not work with SharePoint 2010!  I have no plans at this time to update it to work with SharePoint 2010, but would like to eventually. Please reply below if you are interested in a SharePoint 2010 version and I may get motivated to upgrade it. :)
Licensing
  • There is no license required to use the Hide View All Site Content feature.
  • This is available to the public (business or personal) for free.
  • There is no support.
  • There is no implied or explicit warranty.
  • Use at your own risk.
Downloads
No Coding Required
  • Very easy to install
  • No coding required
  • For those interested in how to install this solution, it is very easy and does not require any coding, compiling, or editing.
  • Detailed installation and activation instructions can be found at the bottom of this article.
What Is The User Experience?
(What does it look like?)

Before (Normal)
After (Hidden)
    
 

Additionally I add a new custom menu item to the Site Action menu.  Here is the result of the new link.  This link will only appear for users having the AddAndCustomizePages right such as designers and administrators.
And finally, this functionality is wrapped up into feature allowing it to be activated or deactivated for each site as needed.  Here is the new feature that will appear in the list of Site Features for a web site.
All of this is wrapped in to a single SharePoint solution package (.wsp) file and can easily be installed on a SharePoint farm by a server administrator.
Note: From this point forward in the document, any reference to the “View All Site Content” link will be abbreviated to “VASC”.
Consideration
There are a couple ways to in which to accomplish this.  The first and most obvious method is to modify the master page that contains this link.  This involves a fairly simple process of modifying the master page and removing the VASC link, then redeploying the new master page.  The drawback from this is that you do have to modify the master page which is sometime not desirable, plus the master page is likely to have more than one site based on it, and it may be desirable to have this View All Site Content link remain on those sites.
However, if you are willing to modify the master page, there is another posting you may find of value.  Keep in mind the security you define in the master page will be the same for all sites on your SharePoint farm.  If that is desirable, you may find this post on SPSecurityTrimmedControl: Conditionally display contents by security of use.
My Approach
I had a couple goals I wanted to my solution to meet.  They were:
1.       To be able to selectively choose the sites where the VASC link is hidden.
2.       Avoid having to modify the master page if possible.
3.       Provide a simple way for users to hide/remove the VASC link.
After a little investigation, a few things about SharePoint (3.0/2007) surfaced that allowed me to achieve all of my goals and provide a solution that can easily be implemented.
Hidden by Style
The approach I have decided to use is to simply hide the VASC link using a style sheet modification.  The VASC link for most, if not all of the sites assigns an ID (ctl00_PlaceHolderLeftNavBar_idNavLinkViewAll) to the anchor tag containing the VASC link.  This makes it easy pretty darn easy hide this link by simply adding a bit of style code to the page.  In fact, just for giggles, you can copy the following style sheet code into a Content Editor Web Part.  This web part can even be strategically placed at the bottom of the page; optionally hide the title bar and nobody would even know it was there.  Here is the sample style to try it just for fun.  This will hide the View All Site Content link on your page.
#ctl00_PlaceHolderLeftNavBar_idNavLinkViewAll
{
   Visibility:hidden;
}
But this is not really good enough.  At least, not alone this isn’t.
I needed a way to do this for every page on a given site.  And copying this code to each and every page on a site is not only extremely tedious; it is almost guaranteed to be incomplete and error prone.  Microsoft Office SharePoint Server (MOSS) 2007 does provide an easy way to do this, but Windows SharePoint Services (WSS) 3.0 does not.  Using MOSS 2007, you can apply a custom style sheet to a web site and optionally apply it to every sub site.  For SharePoint servers where this is desired, and if you are using MOSS 2007, this will work for you.  Also keep in mind; you just removed the VASC link for every user – including your site designers and administrators.  Although this is not the worst of all problems, it is probably not the absolute desired solution either.
I still like the idea of using the custom style code to hide my VASC link.  But I also need to place a link on the page for users who will need easy access to the VASC link such as designers and administrators.  I know I can easily accomplish this by adding an access controlled link to the Site Actions menu, but I will come back to this in a moment.  I still need to address how to easily apply a customized style to every page on a given site.
CustomizeCss
So how can I apply a custom style to every page on a given site?  SharePoint provides a way to do this using the SharePoint object model.  With a bit of custom C# code I use the SPWeb.CustomizeCss method to specify a custom style sheet to be used on every page of my site.
The CustomizeCss method on the SPWeb class provides way to specify the style sheet file name of an existing style sheet used by SharePoint.  SharePoint utilizes a number of different style sheet files.  The one we are interested in is the style sheet file that is applied to each and every page on the site.  One such style file is the core.css file, and this will do just for our needs.  The standard default core.css file is located in …\12\TEMPLATE\LAYOUTS\1033\STYLES.  This STYLES folder is a virtually mapped via the /_layouts virtual directory that is mapped to each and every site in SharePoint.  So, the core.css file is accessible to every site by simply using the URL of “[site-root-url]/_layouts/1033/styles/core.css”.  For every page that SharePoint renders, it renders a link to the core.css using this path.
However, for any site that has been configured to use a custom core.css style sheet via the CustomizeCss method on the SPWeb class, the URL rendered in each page references a core.css file located in a different location.  This is accomplished in C# by the following code where web is an instance of the SPWeb class for the web site of your choice.
web.CustomizeCss(“core.css”);
web.Update();
The CustomizeCss(“core.css”) statement tells SharePoint to use a custom copy of the SharePoint core.css file.  Once this CustomizeCss method is executed, a copy of the core.css file found in the …\12\TEMPLATE\LAYOUTS\1033\STYLES folder is copied to the folder (not a document library) named _styles on the applied site.  The resulting URL to this new core.css file can be found at
“[site-root-url]/_styles/core.css”.  Modifying this core.css file will affect only the current site.
Reverting this site back to using the original global (un-customized) copy of the core.css file can be accomplished just a easy using the following code.
web.RevertCss(“core.css”);
web.Update();
Executing the RevertCss method does not remove the custom core.css file on the web site’s “/_styles” folder.  It simply tells the site to no longer use it and to use the original core.css found in the C:\…\12\TEMPLATE\LAYOUTS\1033\STYLES folder; which is the same folder as the as the “[site-root-url]/_layouts/1033/styles” folder.
So we now know how to use the CustomizeCss and the RevertCss methods on the SPWeb class provide an easy way to point the site to a new custom style sheet file.  Now that we have an easy way to point our site to a custom core.css file, all we need to do is copy our custom core.css file that contains all the original core.css contents plus the extra style code to hide the VASC link and copy it into the _styles folder of the site.  All of this can easily be implemented using a SharePoint feature.  Using a feature provides a standard way to enable or disable functionality with a site in a safe and secure manner.  I won’t cover all the details on how to create the feature here, but the source code provides all the code you need.
Now that we know how to hide the View All Site Content link easily using a feature and the CustomizeCss and RevertCss methods, we need to provide an easy way to allow site designers and administrators to quickly and easily use the View All Site Content link.
Site Action Link
To provide web managers such as designers and administrators with a convenient link equal to the View All Site Content link, we will add a new custom action menu item.  I won’t go into the details of the code and how to create the feature here, but I will briefly cover the expected functionality.  Again, the source code is available for those interested in the technical details.
The Site Action is usually located in the upper right corner of the web site and contains links used by site administrators such as the Site Settings link.  The nice thing about the Site Actions menu is that it is collapse and consumes a minimal amount of screen real estate.  So, adding an additional menu option to the Site Actions menu will not only be convenient for site administrators, it’s pretty easy to implement in a SharePoint feature.  This new View All Site Content link on the Site Action can be secured in a manner that best suits your needs.  In the solution sample I provide, this new View All Site Content link on the Site Actions menu is only visible to users who have the “AddAndCustomizePages” right which allows designers and administrators to see it, but is not visible to typical users of a site.
There are plenty of examples on how to add a custom item to the Site Action menu so I will not cover that in any detail here, but the solution sample I provide does include all the code – and the nice thing is, it isn’t much code.
Installation and Activation
Basic Install Steps:
1 – Add the solution using the STSADM command:
stsadm -o addsolution -filename [path]\VASCSiteAction.wsp

2 – Deploy the solution using the STSADM command:
stsadm -o deploysolution -name VASCSiteAction,wsp -allowgacdeployment -immediate –allcontenturls

3 – Optional – to restart IIS:
iisreset /noforce
Activating the new feature:
1 – Navigate to the site you want to hide the View All Site Content link.
2 – Go to the Site Settings for that site (Site Actions > Site Settings).
3 – Click the Site Features (not the Site Collection Features) link under the Site Administration section.
4 – Activate the new feature named “Hide the View All Site Content link”.
Your View All Site Content link should now be hidden and the View All Site Content link should now appear in the Site Actions menu.
Conclusion
The result is a single feature that a site administrator can activate and deactivate on any web site to hide and show the standard View All Site Content link in the quick launch navigation.  Additionally, it adds a useful new View All Site Content to the Site Actions menu that is visible only to users having the AddAndCustomizePages right on that site


Open SharePoint Central Admin and select the Operations tab.
Select Solution Management.
Click the link to the .wsp solution you just added.
Click Deploy Solution - If the solution is not globally deployed select the web applications you want to deploy to.
Click OK.
The solution is now deployed to the web applications you selected or to all web applications if it deployed globally. This is not the end of the deployment process though. If the solution contains a web part there are still a few steps to go before it will be displayed on your site. To add the web part to a page on your site do the following:
Navigate to the site collection where you want to place the web part and go to Site Settings and Site Collection Features (this assumes that the feature is scoped at the site collection level, sorry for making more assumptions that you understand scopes but that is another post and something that other people have already written plenty about if you want to find out more).
Activate the feature that contains the web part that has been deployed in the solution.
Next, go to Site Settings and Web Parts and click New.
Select the web part to add it to the wbe aprt gallery for that site collection.
The web part is now ready to be added to a page in the usual way - edit page, add web part to zone, browse to web part.
Hope that helps somebody...

No comments:

Post a Comment