Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Am I missing something? It looks like I can't follow a document set in a document library. I can indeed follow any document inside the document set, but not the set itself. Is there a way to enable this?

share|improve this question

1 Answer 1

It does not seem possible to follow Document Set since Social Actor supports only the following types:

  • User A user
  • Document A document.
  • Site A site.
  • Tag A tag

But you could consider the following approach. The idea is to follow Document Set content (files). The solution consists of:

  • getting Document Set files
  • follow files in document set

JavaScript example

function startFollowing(webUrl,fileUrl){
    var endpointUrl = webUrl + "/_api/social.following/follow";
    var actor = {
         "actor":{
             "__metadata":{"type":"SP.Social.SocialActorInfo"},
             "ActorType":1,
             "ContentUri": fileUrl,
             "Id":null
          }
    };         
    return executeRequest(endpointUrl,'POST',null,actor);
}


function getFiles(webUrl,folderUrl){
    var endpointUrl = webUrl + "/_api/web/GetFolderByServerRelativeUrl('" + folderUrl + "')/files";         
    return executeRequest(endpointUrl,'GET');
}


function followFiles(webUrl,folderUrl)
{
    return getFiles(webUrl,folderUrl).then(function(data){
        var files = data.d.results;
        if(files.length == 0) return;
        var fileUrl = webUrl + '/' + folderUrl + '/' + files[0].Name; //server absolute file url
        data = startFollowing(webUrl,fileUrl);
        for (var i = 1; i < files.length; i++) {
          (function (i) {
             data = data.then(function() {
                 fileUrl = webUrl + '/' + folderUrl + '/' + files[i].Name;
                 return startFollowing(webUrl,fileUrl);
             });
          }(i));
        }     
    });
}

where

function executeRequest(url,method,headers,payload) 
{
    if (typeof headers == 'undefined' || headers == null){
        headers = {};
    }
    headers["Accept"] = "application/json;odata=verbose";
    if(method == "POST") {
        headers["X-RequestDigest"] = $("#__REQUESTDIGEST").val();
    }   

    var ajaxOptions = 
    {       
       url: url,   
       type: method,  
       contentType: "application/json;odata=verbose",
       headers: headers
    };
    if(method == "POST") {
      ajaxOptions.data = JSON.stringify(payload);
    }  

    return $.ajax(ajaxOptions);
}

Usage

Assume a Documents library contains Guides document set, then the following example demonstrates how to follow files in document set:

var webUrl = _spPageContextInfo.webAbsoluteUrl;
followFiles(webUrl,'Documents/Guides');
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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