Document set
To create and manage multi-document work products consistently, we can use document set. For this, we need to configure a new document set content type for each multi-document work product, which they typically create.
The document set content type is a folder-based content type, which organizes multiple related documents into a single view, where they can be worked on and managed as a single entity.
Include JS file given below before we execute the function.
sp.documentmanagement.s
Site Collection administrator is there to activate the document sets feature before you create or configure new document set content types.
Go to the top-level site in the Site Collection for which you want to enable document sets.
- Site Actions menu-->click Site Settings.
- Site Collection Administration-->click Site collection features.
- Find document sets in the list and then click Activate.
Call the reusable function
- SP.SOD.executeFunc('sp.documentmanagement.js', 'SP.DocumentSet.DocumentSet', function() {
-
- createfile(_spPageContextInfo.webAbsoluteUrl);
-
- });
- shareimprove this answer
-
- 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("TutorialDocuments");
-
- fileCreateInfo = new SP.FileCreationInformation();
- fileCreateInfo.set_url("/Root Folder/GowthamDocuments/Sample file.docx");
- fileCreateInfo.set_content(new SP.Base64EncodedByteArray());
- fileContent = url;
-
- for (var i = 0; i < fileContent.length; i++)
- {
- fileCreateInfo.get_content().append(fileContent.charCodeAt(i));
- }
-
- this.newFile = oList.get_rootFolder().get_files().add(fileCreateInfo);
- clientContext.load(this.newFile);
- clientContext.executeQueryAsync( Function.createDelegate(this, successHandler), Function.createDelegate(this, errorHandler));
-
- function successHandler()
- {
- console.log(" New File Added!");
- }
-
- function errorHandler()
- {
- console.log("File Creation Failed: " + arguments[1].get_message());
- }
- }
Thanks for reading my blog. Please post your feedback.