Hi All,
In a following post we will
see about how to get the documents/Items inside the Folder in SharePoint
document library.
Below code is developed in
SharePoint hosted apps.In a below Example ,I get the Items from "Shared Documents"(Library Name) and "Folder1" is my folder inside the document Library.
'use strict';
var SPAppWebUrl;
var spHostUrl;
(function
() {
// This code runs when the DOM is ready
and creates a context object which is
// needed to use the SharePoint object
model
$(document).ready(function () {
spHostUrl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
SPAppWebUrl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));
SP.SOD.executeFunc("sp.js", "SP.ClientContext", function () {
SP.SOD.executeFunc("sp.runtime.js", "SP.ClientContext",
function () {
$.getScript(spHostUrl + "/_Layouts/15/SP.RequestExecutor.js", function (data) {
MainFunction();
});
});
});
});
function MainFunction() {
$('#btnGet').on('click', function
() {
getFolderCount()
});
}
function getFolderCount() {
var url = SPAppWebUrl + "/_api/SP.AppContextSite(@target)" +
"/web/getfolderbyserverrelativeurl('/Shared
Documents/Folder1')/files?" +
"@target='" + spHostUrl + "'";
var executor = new
SP.RequestExecutor(SPAppWebUrl);
executor.executeAsync({
url: url,
method: "GET",
headers: { "Accept":
"application/json;odata=verbose" },
// return data format
success: onQuerySuccess,
error: onQueryError
});
function onQuerySuccess(data) {
var
jsonObject = JSON.parse(data.body);
var
results = jsonObject.d.results;
//count inside the folder
alert(results.length);
if
(results.length !== null) {
//Looping
Jason data and get the documents
$.each(results, function (index) {
alert(results[index].Name);
alert(results[index].ServerRelativeUrl);
});
}
}
function onQueryError(error) {
alert("Error:
" + error.statusText);
}
}
function
getQueryStringParameter(urlParameterKey) {
var params = document.URL.split('?')[1].split('&');
var strParams = '';
for (var
i = 0; i < params.length; i = i + 1) {
var
singleParam = params[i].split('=');
if
(singleParam[0] == urlParameterKey)
return
decodeURIComponent(singleParam[1]);
}
}
})();
Thanks.
Related Post
REST API
- Internet Explorer cannot display this feed - while accessing REST URL in SharePoint
- XMLHttpRequest: Network Error 0x2eff, Could not complete the operation due to error 00002eff.
- Add Attachment to the List Item Using REST API in SharePoint
- Insert Items into List by using REST API in SharePoint 2013
- Read List Items using REST API
SharePoint
- Build Automation (CICD) of WebJob in SharePoint Online
- List view render using JSLink with Fabric UI
- Delete Quick Links using Powershell
- SharePoint Interview Questions and Answers..
- Issues:SharePoint Foundation 2013 Prerequisites installation(off line) on Windows Server2012 R2
- SharePoint Column Field Types
- Alternate to InfoPath Forms in SharePoint
- SharePoint 2016 [Beta] Release Date
- SharePoint Modal Dailoge to Open Page
- What is Look up Column and how to use in SharePoint 2010,2013
- People Picker Check User Entry and Resolve
- How to Get User Data from AD (Active Directory) in SharePoint Using C#
- History of SHAREpoINt
- How to Create Application Page in SharePoint using Visual Studio 2010,2013
- Retrieve Site Features in SharePoint
- Weather Webpart by using Yahoo Service in Share Point
- Activate Telnet Client in Windows Server
- Navigate to another Page After Clicking on JavaScript Alert
- How to read List Item Version Collection Programmatically
- How to get Worker Process from Command Prompt
- How to Use DataTable.js in SharePoint webpart
- Adding New Link to PromotedActions Delegate Control in SharePoint 2013
- How to Deploy Master Page in Share Point
- Get Role Definition in SharePoint
0 comments:
Post a Comment