I have implemented a custom upload button on a modified 'docsethomepage.aspx'. The new page shows the properties of the DS.

I would like using javascript to upload the file to this Doc set instead to the Documents Folder.

I am following the great help found in here I would 'only' need to change the path from Documents to this Document Set. The Query Strings in the URL have these IDs available:

ID, FolderCTID, List and RootFolder of which I suspect need to use.

I am trying to fiddle with the uploadFile function but so far failed. Your help much appreciated.


var fileInput ;

        fileInput = $("#getFile");  
        SP.SOD.executeFunc('sp.js', 'SP.ClientContext', registerClick);  

    function registerClick()  
        //Register File Upload Click Event  
    var arrayBuffer;  

    function readFile()  
        //Get File Input Control and read th file name  
        var element = document.getElementById("getFile");  
        var file = element.files[0];  
        var parts = element.value.split("\\");  
        var fileName = parts[parts.length - 1];  
        //Read File contents using file reader  
        var reader = new FileReader();  
        reader.onload = function(e)  
            uploadFile(e.target.result, fileName);  
        reader.onerror = function(e)  
    var attachmentFiles;  

    function uploadFile(arrayBuffer, fileName)  
        //Get Client Context,Web and List object.  
        var clientContext = new SP.ClientContext();  
        var oWeb = clientContext.get_web();  
        var oList = oWeb.get_lists().getByTitle('Documents');  
        //Convert the file contents into base64 data  
        var bytes = new Uint8Array(arrayBuffer);  
        var i, length, out = '';  
        for (i = 0, length = bytes.length; i < length; i += 1)  
            out += String.fromCharCode(bytes[i]);  
        var base64 = btoa(out);  
        //Create FileCreationInformation object using the read file data  
        var createInfo = new SP.FileCreationInformation();  
        //Add the file to the library  
        var uploadedDocument = oList.get_rootFolder().get_files().add(createInfo)  
        //Load client context and execcute the batch  
        clientContext.executeQueryAsync(QuerySuccess, QueryFailure);  

    function QuerySuccess()  
        console.log('File Uploaded Successfully.');  

    function QueryFailure(sender, args)  
        console.log('Request failed with error message - ' + args.get_message() + ' . Stack Trace - ' + args.get_stackTrace());  

1 Answer 1


In the end this was simply achieved by updating the SP.FileCreationInformation object set url to createInfo.set_url("http://mySPServer/sites/mytest/mydocLibrary/DocSetName/myfile.txt");

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.