Home > SharePoint > Hide view menu items in Moss 2007 to not admin users

Hide view menu items in Moss 2007 to not admin users


The branding and customization of an Moss 2007 intranet site requires in most cases some hard work, because the original interface is rich of appreciated features (for example the dynamic filtering on Choice fields in the OOB views) that could be very hard to replicate in a custom web part.

But there are drawbacks: for example the “Out Of the Box”(OOB) List and Document Library view interface has the possibility of to define many views , that sometimes has to be considered of internal service (for example a custom page with some web parts based on specific views) which is not appropriated , confusing and sometimes even dangerours that the normal user (not administrator) could choose from the view selector.

In the above image for example most users find confusing and don’t understand what is the “Explorer View”, and you can have some view for internal uses as “viewTest”, not speaking of what can be dangerous that a user can create his own view (the “Create View” is normally hidden by default to not admin users)

The view permissions management is an highly requested but lacking feature in the OOB Moss.

Searching on internet i have found some free solutions as the Infowise Smart list lite.

This feature create a link for to manage the view permissions in the Document library / List settings (in my case a document library)


But unfortunately on the customer test environment clicking on the link has caused an error about a resource in a resource file.

I have tried to uninstall, restart the server, reinstall the solution (as suggested from InfoWise support) but no luck.

So, giving the fact that the feature was highly requested, i have tried the solution of hiding the view menu items working on the produced HTML.

For the first thing it was necessary to know if the logged user is an administrator or normal user: in a previous post i have demonstrated how to create a custom web service, so the first step was to create a simple custom web service that tells me if the user is an admin, the code is very simple:

public bool CurrentUserIsAdmin()
    SPSite objSite = SPContext.Current.Site;
    using (SPWeb objWeb = objSite.OpenWeb())
        return objWeb.CurrentUser.IsSiteAdmin;

The next problem is how to access the view selector.

Using Firebug in the Firefox browser i have searched in the html the names of my SharePoint views and i have seen that my view items are <ie:menuitem> items , enclosed in a div with style display:none under a td with style ms-viewselector, and , the most important, we have a main “menu” with “id” ending in “_ViewSelectorMenu”, and in the page is the only element with this id

So i have created an service.asmx for my custom web service , i call it after the page loading using Jquery:


function setVisibilityViewByPerms(){
    var strCtxMainHttpRoot = ctx.HttpRoot ;
    var strSoap = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><CurrentUserIsAdmin xmlns="http://tempuri.org/" /></soap:Body></soap:Envelope>';
        url: strCtxMainHttpRoot + "/_layouts/Service.asmx",
        type: "POST",
        dataType: "xml",
        data: strSoap,
        complete: wsVerifyVisibilityCompleted,
        contentType: "text/xml; charset=\"utf-8\""

function wsVerifyVisibilityCompleted(xData, status) {
    if (status == "success"){
        // xData.responseXML.text returns "true" "false"
        var boolUserIsAdmin = (xData.responseXML.text === "true"); // trick in order to have a bool value in js
        var objDivListViews = $("menu[id*=_ViewSelectorMenu]");
        var strItemMenuText = "";
        var objAnchors = objDivListViews.find("ie\\:menuitem").each(function(index){
           //window.alert(index + ":" + $(this).attr("text"));
           strItemMenuText = $(this).attr("text");
               // this part must be customized view by view ...............
               if (strItemMenuText == "Create View" || strItemMenuText == "Explorer View" || strItemMenuText == "viewTest"){
        if (xData.responseXML != undefined)
            window.alert("Error. call assistance, problem with setVisibilityViewByPerms.");           

With the syntax $(“menu[id*=_ViewSelectorMenu]” we obtain a reference to our element with the id ending with _ViewSelectorMenu (“*=” is the Jquery syntax for to find elements that contains the string); in this element we search every ie:menuitem with the Jquery “find” function.

If the user is not an administrator (“!boolUserIsAdmin”) we obtain the “text” attribute for every ie:menuitem, if the name corresponds to an item that should not be viewed from not admin users it is used the Jquery “remove” functions and the item is no more available in the views list.

In this case the views name are cabled, for complex scenarios could be extended the custom web service , for example using a custom configuration list.

Categories: SharePoint
%d bloggers like this: