This article shows you how to list out the files from the top folder of the library with the checkout status of each files and to whom the document is checked out.

To do this, we will pass the list name as a parameter to the script.

HTML Snippet

  1. <!-- Style required for HTML Snippet -->
  2. < style type = "text/css" >
  3. .lst - table th
  4. {
  5. background - color: #ddd;
  6. border: 2 px solid# fff;
  7. text - align: left
  8. }
  9. .lst - table td
  10. {
  11. background - color: #eee;
  12. border: 2 px solid# fff;
  13. }
  14. .web - heading
  15. {
  16. padding: 2 px;
  17. } < /style>
  18. <!--Include jQuery library to perform dynamic html dom manipulation -->
  19. < script type = "text/javascript" src = "/siteassets/jquery.js" > < /script> < div >
  20. < h2 class = "web-heading" > Files with checked - out Status < /h2> < div id = "fldrUrl" > < /div> < /div> < table width = "100%"
  21. cellpadding = "10"
  22. cellspacing = "2"
  23. id = "lstTable"
  24. class = "lst-table" >
  25. < thead >
  26. < tr >
  27. < th > File Name < /th> < th > Checked - out Status < /th> < th > Checked - out By < /th> < /tr> < /thead> < tbody > < /tbody> < /table>
JavaScript Snippet
  1. <script type="text/javascript">
  2. functiongetcheckoutStatus(listname)
  3. {
  4. varclientContext = SP.ClientContext.get_current();
  5. if (clientContext != undefined && clientContext != null)
  6. {
  7. varwebSite = clientContext.get_web();
  8. this.list = webSite.get_lists().getByTitle(listname);
  9. this.folder = this.list.get_rootFolder();
  10. this.files = this.folder.get_files();
  11. clientContext.load(this.folder);
  12. clientContext.load(this.files, 'Include(CheckOutType,Name,CheckedOutByUser)');
  13. clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));
  14. }
  15. }
  16. functionOnLoadSuccess(sender, args)
  17. {
  18. varfilesEnumerator = this.files.getEnumerator();
  19. $('#fldrUrl').html("Folder URL: " + _spPageContextInfo.webAbsoluteUrl + this.folder.get_serverRelativeUrl());
  20. while (filesEnumerator.moveNext())
  21. {
  22. varcurrentFile = filesEnumerator.get_current();
  23. vartrow = "";
  24. trow += "<tr>";
  25. trow += "<td>" + currentFile.get_name() + "</td>";
  26. if (currentFile.get_checkOutType() < 2)
  27. {
  28. trow += "<td>" + currentFile.get_checkOutType() + " - Yes" + "</td>";
  29. trow += "<td>" + currentFile.get_checkedOutByUser().get_title() + "</td>";
  30. } else {
  31. trow += "<td>" + currentFile.get_checkOutType() + " - No" + "</td>"
  32. trow += "<td></td>";
  33. }
  34. trow += "</tr>";
  35. //Append each list to the table as a row
  36. $("#lstTabletbody").append(trow);
  37. }
  38. }
  39. functionOnLoadFailed(sender, args)
  40. {
  41. try
  42. {
  43. console.log('Error: ' + args.get_message() + '\n' + args.get_stackTrace());
  44. } catch (err) {}
  45. }
  46. functioninjectMethod()
  47. {
  48. getcheckoutStatus("Site Pages");
  49. }
  50. ExecuteOrDelayUntilScriptLoaded(injectMethod, "sp.js");
  51. </script>
Add the snippet to the content editor as I mentioned in this article. Either you can also try the code in SharePoint add-in to get the following result.

Output:

Output

Enjoy the exploring of new possibilities.