I just added a button to my Document Set Home Page that is supposed to copy a fixed small file stored in ../../SiteAssets/min.png and adds it to the documents of this DS.

So far I was able to store in my DocumentSet Library. Would need to go deeper to current Document set.

I can get the Query Parameters using:

//get the querystring from the Document Set url and split into an array
 function getVariables() {  
   var variables = {};  
   var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { variables[key] = value; });  
   return variables;  
 //get the items   
 var listID = getVariables()["List"]  
 var rootFolder = getVariables()["RootFolder"];  

I need to adjust something here, instead of pointing to 'MyDocumetLibrary':

    // Get the ClientContext for the app web
    var clientContext = new SP.ClientContext.get_current();

    //get lib from its name
    var parentList = clientContext.get_web().get_lists().getByTitle("MyDocumetLibrary");

<script type="text/javascript">  

function createfile (url)   
    var clientContext;  
    var oWebsite;  
    var oList;  
    var fileCreateInfo;  
    var fileContent;  

    clientContext = new SP.ClientContext.get_current();  
    oWebsite = clientContext.get_web();  
    oList = oWebsite.get_lists().getByTitle("MyDocmentSetLibrary"); 

    fileCreateInfo = new SP.FileCreationInformation();  
// This just make filename unique       
var filename =  Math.floor((Math.random() * 100000) + 1) + 'Minute.xyz';
        fileCreateInfo.set_content(new SP.Base64EncodedByteArray());  
        fileContent = url;  

    for (var i = 0; i < fileContent.length; i++)   

    this.newFile = oList.get_rootFolder().get_files().add(fileCreateInfo);  
    clientContext.executeQueryAsync( Function.createDelegate(this, successHandler), Function.createDelegate(this, errorHandler));  

    function successHandler()   
       console.log("FILE CREATED!");

    function errorHandler()   
       console.log("File Creation Failed: " + arguments[1].get_message());  


http://mysite/sites/mytest/SiteAssets/min.png');" />

Any help much appreciated!


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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