I want to navigate into a folder in SharePoint and create there a File. I can already create a file on the "root" folder of a selected list.

However I can't "switch" into a specific folder (document set) which is in the root folder.

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

folderPath = getParameterByName('RootFolder');
var folderPathArray = folderPath.split('/');
var documentSetName = folderPathArray[folderPathArray.length -1];

var encodedFolderPath = [];
folderPathArray.forEach(function (element) {
folderPath = encodedFolderPath.join("/");

fileCreateInfo = new SP.FileCreationInformation();
fileCreateInfo.set_url(folderPath + title + ".aspx");
fileCreateInfo.set_content(new SP.Base64EncodedByteArray());

fileContent = "helloworld";

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

// how to call get_files() in a document set so I can use the add method like below?
this.newFile = oList.get_rootFolder().get_files().add(fileCreateInfo);

var realFolder = oList.get_rootFolder().getByTitle("Special Folder");


clientContext.executeQueryAsync(onsuccess, onfailedownError');


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.