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

I have a requirement to check for duplicate documents in the document library. How can i implement this using jquery. Please share the code.

share|improve this question
1  
why would you do that? what is duplicate document? Did you read the How to Ask page? Did you visit whathaveyoutried.com ? –  Steve B Jul 3 '12 at 13:35
    
i have a requirement where in i was uploading a document into a doc lib using custom code. So whenever i do that i wanted to check if the user is uploading a unique doc. –  AJ Mania Jul 4 '12 at 19:56
    
Unique in what way? Filename? Contents (I suppose creating a hash and comparing it to the hash of files in the library)? –  shufler Jul 4 '12 at 20:55

1 Answer 1

Code to check if the document exists in the doc lib using jquery

function findDocument(fileName, docLibName) {
        var optValue = "0";
        var query = "<Query><Where><Eq><FieldRef Name='FileLeafRef' /><Value Type='File'>" + fileName + "</Value></Eq></Where></Query>";

        $().SPServices({
            operation: "GetListItems",
            listName: docLibName,
            CAMLViewFields: "<ViewFields><FieldRef Name='ID' /></ViewFields>",
            CAMLQuery: query,
            async: false,

            completefunc: function (xData, Status) {
                    optValue = $(xData.responseXML).SPFilterNode("rs:data").attr("ItemCount");
            }
        });
        return optValue;
    }
share|improve this answer
    
You'll need to fix the formatting of your answer as right now it looks like this returns the number of documents in a library because you're missing a some spaces in the markdown. (When I edit the post I see you're performing a query based on a supplied file name, and I can't save my edit of four spaces). –  shufler Jul 4 '12 at 20:56
    
yes, i am returning the count. So i check that if the count is more than 0, that implies that the document exists. –  AJ Mania Jul 5 '12 at 10:21

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.