cancel
Showing results for 
Search instead for 
Did you mean: 

Want to restrict multiple uploads of same file in Alfresco 7.0.1

shivam1sharma
Champ on-the-rise
Champ on-the-rise

We are using Alfresco 7.0.1, when we upload same file multiple times under document library of any site , it gets uploaded and name got updated with a counter like example-1.png.

We want to restrict the multiple upload of same file with a message like "document already exists".
Is there any simple way to implement this?

Please suggest if any.

3 REPLIES 3

sanjaybandhniya
Elite Collaborator
Elite Collaborator

You can restrict by writing rule or policy.

I am creating a rule for documentlibrary of the site.

I am executing the script when a document is created or enter,

Script is :

function main() {
    // Check if this is a new document creation.
    if (document.isContainer || !document.isDocument) {
        return;
    }

    var folder = document.parent;
    var fileName = document.name;
   
    for (var i = 0; i < folder.children.length; i++) {
   
        if ((folder.children[i].isDocument) && (folder.children[i].name == fileName) && (String(folder.children[i].nodeRef)!=String(document.nodeRef))) {
           
            throw "A file with the"+ fileName + folder.children[i].nodeRef + document.nodeRef +(String(folder.children[i].nodeRef)!=String(document.nodeRef))+" name already exists in this folder. Please choose a different name.";            
        }
    }
}

main();
 
 
 
Please help me with the script.

Hello, the Rule in this case not prevent the creation of the document with the same name, you most implement a NodeServicePolicies.