4

I need to have a tree view for a folder "Demo" from a SharePoint document library . The tree view should display all folder inside doc lib "Demo" and on right side i need all items within the folder . Further i need to set permissions on folders ,so only users having access to folders can do add/edit/delete .

  1. Can this be achieved OOTB ?
  2. if i create a custom webpart , how can i do this client side ? Is it possible ?
  3. Are there any third party tools available for this req ?
  4. How to achieve folder level permission ?
3
  • 2
    your customer wants to make SharePoint 2013 look like windows XP. is there a business logic to that requirement? The cost of training users on the new interfaces would probably be lower than developing this or buying 3rd party products to achieve it. I'd suggest you lookup "the 5 whys" and try to get away from doing this work at all Sep 4, 2015 at 7:25
  • We are trying to move from documentum to SharePoint. Documentum has all this folder options .
    – Nikhil J
    Sep 4, 2015 at 21:00
  • Changing document management systems is always a transformation challenge. But surely there are reasons why Documentum is being dropped. Did you go over a taxonomy review? Is the extra security on folders required by a risk management reason, or is there a business justification for keeping the barriers between the different information silos that those secure folders represent? Could you look at restructuring the IA so that security would be a library level only and use metadata navigation below that? Open, collaborative, Work-Out-Loud are reasons for change. Technology is only a part of it. Sep 6, 2015 at 23:46

3 Answers 3

8
+50

To add a treeview to a document library view, follow these steps:

  1. Browse to the view you want to add the treeview to. This must be a listview page (i.e. it won’t work on default .aspx or home.aspx).

  2. Edit the page in SharePoint Designer — then click Advanced Mode.

  3. Add a table to PlaceHolderMain with one row and two columns as shown below (NOTE: ” ” SharePoint doesn’t like these quotes. You need to change them all back to standard double-quotes " ".):

    <table style="width: 100%">
    <tr valign="top">
    <td width="20%">
    </td>
    <td>
    </td>
    </tr>
    </table>
    
  4. Move the existing Webpart Zone (the one that contains the view) and all its content to the second you just added.

  5. Add the following to the first you just added (the one whose width is 20%). Again make sure all the double-quotes get pasted properly!

    <SharePoint:SPHierarchyDataSourceControl id="doclibDataSource" runat="server" RootContextObject="List" ShowFolderChildren="true" EnableViewState="false">
    </SharePoint:SPHierarchyDataSourceControl>
    <SharePoint:SPTreeView ID="doclibtreeview" runat="server" DataSourceID="doclibDataSource" EnableViewState="false" ExpandDepth="2" SelectedNodeStyle-CssClass="ms-tvselected">
    </SharePoint:SPTreeView>
    

Save the page, and then view it in your browser:

See link


For item level permissions you need to break permissions (stop inheriting permissions) on each folder.

  1. Click on folder and click on ...
  2. Click again on ...
  3. Click Shared with
  4. Click Advanced
  5. Break permissions Stop Inheriting Permissions
  6. Set new permissions for that folder
  7. Repeat 1.-6. for other folders
2

Out of the box there is no 'tree-view' view of items inside a library or list. If you have your (network) permissions correctly configured it is possible to open a SharePoint list inside 'Windows Explorer'

You can create a custom webpart to implement this functionality.

There are some 3rd party tools available. One of them is from Bamboo solutions. I never tried this particular web part. Bamboo Solutions is a known web part vendor in the SharePoint world. http://store.bamboosolutions.com/sharepoint-tree-view-web-part.aspx

To enable folder level permissions (aka item level permissions) you need to break the permission inheritance. Go to the settings of the list -> Permissions -> and click 'stop inheriting permissions' Warning: This has a performance impact! Please read some articles about breaking permission inheritance and about the limitations of 'item level security' enabled lists!!!

Tip: try to avoid working with folders in SharePoint lists and libraries but use metadata (columns, site columns, ...). See a folder name as metadata and not as a container. Using metadata instead of folders gives you a whole range of new content management possibilities in search, views etc.

1
  • Nice tip for metadata ;)
    – Marko Tica
    Sep 4, 2015 at 7:32
1

In my opinion you should go with custom web part. Your requirement is fairly simple, but the amount of work to create a custom web part that too with security trimming will surely turn this task into a Mammoth.

You can follow a simple approach.

Set unique permissions on your Doc Lib
            |
            |
           \|/
Create a custom web part to pull folders and show files inside it

The above approach can be achieved via Client Side Object Model using c#/JavaScript/PowerShell

Step 1: Set unique permissions on the Document Library for groups and users, by breaking role inheritance.

Refer Assigning Folder Permissions with JSOM and SharePoint Item Level Permissions using PowerShell and CSOM

Step 2: Here you create a custom web part which first retrieves all folders from your document library and display it in Tree View, While creating a tree structure we also check if current user has permissions on it or not?

Get Folders: Sample code to get all folders inside a document library, refered from Get all Folders using Javascript client object model

function GetFolders()
{
    var context = new SP.ClientContext.get_current();
    var web = context.get_web();
    var list = web.get_lists().getByTitle('DocumentLibraryName');
    var query = SP.CamlQuery.createAllFoldersQuery();
    this.allItems = list.getItems(query);
    context.load(allItems);
    context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
}

function success()
{
    var FolderNames = "";
    var ListEnumerator = this.allItems.getEnumerator();
    while(ListEnumerator.moveNext())
    {
        var currentItem = ListEnumerator.get_current();
        var _contentType = currentItem.get_fileSystemObjectType();
        if(currentItem.get_fileSystemObjectType() == '1')
        {
            FolderNames  += currentItem.get_item('Title')+ '\n';
            checkPermission(currentItem.get_item('ID'))
        }
    }

}
function failed(sender, args)
{
    alert("failed. Message:" + args.get_message());
}

Check Permissions on folder: In the success function of Get Folder, you must check whether this current folder has permissions for the current logged in user. For this we call checkPermission(listItem_id)

Refer EffectiveBasePermissions for ListItems

function checkPermission( listItem_id ) {
    var spList = context.get_web().get_lists().getByTitle( listTitle );
    var spListItem = spList.getItemById( listItem_id );
    context.load( spListItem );
    context.load( spListItem , 'EffectiveBasePermissions' );
    context.executeQueryAsync(
        // OnSuccess
        function ( sender , args ) {

            var listItem_id = spListItem.get_id().toString();
            var listItem_Title = spListItem.get_item('Title');
            var listItem_AssignedTo_RAW = spListItem.get_item('Assigned_x0020_To');

            var listItem_HasEditPerms = spListItem.get_effectiveBasePermissions().has(SP.PermissionKind.editListItems);

            ShowFolderInTreeView( listItem_id , listItem_Title , listItem_HasEditPerms );
        },
        // OnFailure
        function ( sender , args ) {
                    alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
        }
    );
}

On Click of Folder leaf: Now once you have created a tree view of folders, then onclick of each leaf you can call a function which pulls files for that folder. Referred from Get Files from a Folder using JavaScript client object model

function ViewAllFiles()
{
    var context = new SP.ClientContext.get_current();
    var web = context.get_web();
    var list = web.get_lists().getByTitle('Shared Documents');
    var query = SP.CamlQuery.createAllItemsQuery();
    query.set_folderServerRelativeUrl('/Shared%20Documents/TestFolder');
    this.allItems = list.getItems(query);
    context.load(allItems, 'Include(Title, ContentType, File)');
    context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
}

function success()
{
    var fileUrls = "";
    var ListEnumerator = this.allItems.getEnumerator();
    while(ListEnumerator.moveNext())
    {
        var currentItem = ListEnumerator.get_current();
        var _contentType = currentItem.get_contentType();
        if(_contentType.get_name() != "Folder")
        {
            var File = currentItem.get_file();
            if(File != null)
            {
                fileUrls += File.get_serverRelativeUrl() + '\n';
            }
        }
    }
    alert(fileUrls);
}

function failed(sender, args) {
    alert("failed. Message:" + args.get_message());
} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.