1

I have a Templates document library, where the piece of code below has happily forcing the download of a template document instead of the file been opened. However, it has stopped working.

The reason for needing to force download is that users actually need a copy of the template and don't need to open the actual original template. (There is an approval workflow, as part of a QMS, which manages the templates and tracks the version, users accidentally interfere with this otherwise).

If any user clicks on a file name currently they see this error message (which isn't really telling us anything, other than the code is not rerouting the 'open file' request to a 'download document' request:

file not found

Here is the code that is being used:

n.b. there is a Templates Editors group for certain users who have permission to edit the templates in order to keep them updated. For everyone else -> force download.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script><script src="/uk_qhse/Style%20Library/jquery.SPServices-0.7.2.min.js" type="text/javascript">
</script><script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function(){
  jQuery().SPServices({  
      operation: "GetGroupCollectionFromUser",  
      userLoginName: jQuery().SPServices.SPGetCurrentUser(),  
      async: false,  
      completefunc: function(xData, Status) { 
        //if current user is not a member of this group...       
        if(jQuery(xData.responseXML).find("Group[Name='Templates Editors']").length != 1)  
        {  
           //force download file on click
           jQuery("a[onclick*='DispEx']").each( function(data){
            var href = this.href;
            this.href = '/uk_qhse/_layouts/download.aspx?SourceURL=' + this.href;
            });
            jQuery("a[onclick*='DispEx']").removeAttr('onclick');  
        }  
      }  
    });  
});
</script>

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.