Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Retrieve Files From A Document Set in SharePoint 2016 Using Java Script Object Model
WhatsApp
Priyaranjan K S
8y
19.5
k
0
1
25
Blog
Document sets can be used when you want to group together the documents within a particular library. Document set by itself is a content type, which acts as a folder at a high level. Apart from the logical grouping of the documents, we can also assign the metadata and assign Workflows to run on a group of documents. In addition to it, we can set the default content to a document set, so that whenever a document set is created, the default contents will be created along with it. This is quite helpful because it gives a starting point to the team. Document set was first introduced in SharePoint 2010 and has made its way all the way until SharePoint 2016.
Document sets are part of a site collection feature.
Let’s try to retrieve all the documents from a document set using JavaScript Object Model.
<
script
language
=
"javascript"
type
=
"text/javascript"
src
=
"//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"
>
</
script
>
<
script
language
=
"javascript"
type
=
"text/javascript"
>
$(document).ready(function() {
var
scriptbase
=
_spPageContextInfo
.webServerRelativeUrl + "/_layouts/15/";
$.getScript(scriptbase + "SP.Runtime.js", function() {
$.getScript(scriptbase + "SP.js", function() {
$.getScript(scriptbase + "SP.DocumentManagement.js", createDocumentSet);
});
});
});
var docSetFiles;
function createDocumentSet() {
//Get the client context,web and library object.
clientContext
=
new
SP.ClientContext.get_current();
oWeb
=
clientContext
.get_web();
var
oList
=
oWeb
.get_lists().getByTitle("Demo Library");
clientContext.load(oList);
//Get the root folder of the library
oLibraryFolder
=
oList
.get_rootFolder();
var
documentSetFolder
= "/sites/Playground/Demo%20Library/Long Term Execution
Planning ";
//Get the document set files using CAML query
var
camlQuery
=
SP
.CamlQuery.createAllItemsQuery();
camlQuery.set_folderServerRelativeUrl(documentSetFolder);
docSetFiles
=
oList
.getItems(camlQuery);
//Load the client context and execute the batch
clientContext.load(docSetFiles, 'Include(File)');
clientContext.executeQueryAsync(QuerySuccess, QueryFailure);
}
function QuerySuccess() {
//Loop through the document set files and get the display name
var
docSetFiles
docSetFilesEnumerator
= docSetFiles.getEnumerator();
while (docSetFilesEnumerator.moveNext()) {
var
oDoc
=
docSetFilesEnumerator
.get_current().get_file();
console.log("Document Name : " + oDoc.get_name());
}
}
function QueryFailure() {
console.log('Request failed - ' + args.get_message());
}
</
script
>
We can add the above script to a Content Editor Web part and see the output in the Console, as shown below:
Summary
Thus, we saw how to retrieve the documents from a Document Set in SharePoint 2016, using JavaScript Object Model.
A Document Set
Java Script Object Model
Retrieve Files
SharePoint 2016
Up Next
Upload/Download A Document In SharePoint2013 Document List Using Client Object Model
Ebook Download
View all
SharePoint Online And Office 365 Administration
Read by 3.6k people
Download Now!
Learn
View all
Membership not found