exclude folder from results in SharePoint rest api
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
I am using rest api to get the list of all files inside a document library
However this also brings the list of all folders
Is there a way to filter out the folders and bring only the files using rest api?
$.ajax(
url: _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/getbytitle('Document Library Name')/items?$top=1000&$select=Title,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText",
headers: "Accept": "application/json; odata=verbose" ,
cache: false,
success: function (data)
//some code
,
error: function (xhr)
console.log(xhr);
);
rest sharepoint-rest-api
add a comment |Â
up vote
1
down vote
favorite
I am using rest api to get the list of all files inside a document library
However this also brings the list of all folders
Is there a way to filter out the folders and bring only the files using rest api?
$.ajax(
url: _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/getbytitle('Document Library Name')/items?$top=1000&$select=Title,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText",
headers: "Accept": "application/json; odata=verbose" ,
cache: false,
success: function (data)
//some code
,
error: function (xhr)
console.log(xhr);
);
rest sharepoint-rest-api
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am using rest api to get the list of all files inside a document library
However this also brings the list of all folders
Is there a way to filter out the folders and bring only the files using rest api?
$.ajax(
url: _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/getbytitle('Document Library Name')/items?$top=1000&$select=Title,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText",
headers: "Accept": "application/json; odata=verbose" ,
cache: false,
success: function (data)
//some code
,
error: function (xhr)
console.log(xhr);
);
rest sharepoint-rest-api
I am using rest api to get the list of all files inside a document library
However this also brings the list of all folders
Is there a way to filter out the folders and bring only the files using rest api?
$.ajax(
url: _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/getbytitle('Document Library Name')/items?$top=1000&$select=Title,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText",
headers: "Accept": "application/json; odata=verbose" ,
cache: false,
success: function (data)
//some code
,
error: function (xhr)
console.log(xhr);
);
rest sharepoint-rest-api
rest sharepoint-rest-api
asked 1 hour ago
Vignesh Subramanian
1,48032053
1,48032053
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
1
down vote
you can use this snip of code to filter your results and exclude Folders
var g;
$.ajax(
url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/Lists/GetByTitle('Training Material')/Items",
type: 'GET',
dataType: "json",
headers:
"Accept": "application/json;odata=verbose",
"content-type": "application/json; odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
,
success: function (data)
for (var i = 0; i < data.d.results.length; i++)
if (data.d.results[i].FileSystemObjectType != 1)
,
error: function (request, error)
console.log(JSON.stringify(request));
);
The above code will return all the items of document library including folders. So, to exclude folders, we can use FileSystemObjectType
property to determind whether the current item is folder or file. For more information on FileSystemObjectType, visit This Link
add a comment |Â
up vote
1
down vote
You have to change the REST URL and point to the document library.
data.Files property will contain only the files and data.Folders will contain the folders.
var RestUrl= _spPageContextInfo.webAbsoluteUrl+ "/_api/Web/GetFolderByServerRelativeUrl('/Shared%20Documents')?$expand=Folders,Files"; //document library name
$.getJSON(RestUrl,function(data,status,xhr)
if(data.Files.length > 0)
var results = data.Files;
);
The above code is tested and works fine.
add a comment |Â
up vote
0
down vote
A few more options actually available:
items?$top=1000&$select=Title,FileLeafRef,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText&$filter=FSObjType eq 0
FSObjType
(display name Item Type
) is a built-in field, values are based on this enumeration
OR
items?$top=1000&$select=Title,FileLeafRef,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText&$filter=startswith(ContentTypeId, '0x0101')
Later approach uses content type and filters out only items which are File-based content type (0x0101
)
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
you can use this snip of code to filter your results and exclude Folders
var g;
$.ajax(
url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/Lists/GetByTitle('Training Material')/Items",
type: 'GET',
dataType: "json",
headers:
"Accept": "application/json;odata=verbose",
"content-type": "application/json; odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
,
success: function (data)
for (var i = 0; i < data.d.results.length; i++)
if (data.d.results[i].FileSystemObjectType != 1)
,
error: function (request, error)
console.log(JSON.stringify(request));
);
The above code will return all the items of document library including folders. So, to exclude folders, we can use FileSystemObjectType
property to determind whether the current item is folder or file. For more information on FileSystemObjectType, visit This Link
add a comment |Â
up vote
1
down vote
you can use this snip of code to filter your results and exclude Folders
var g;
$.ajax(
url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/Lists/GetByTitle('Training Material')/Items",
type: 'GET',
dataType: "json",
headers:
"Accept": "application/json;odata=verbose",
"content-type": "application/json; odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
,
success: function (data)
for (var i = 0; i < data.d.results.length; i++)
if (data.d.results[i].FileSystemObjectType != 1)
,
error: function (request, error)
console.log(JSON.stringify(request));
);
The above code will return all the items of document library including folders. So, to exclude folders, we can use FileSystemObjectType
property to determind whether the current item is folder or file. For more information on FileSystemObjectType, visit This Link
add a comment |Â
up vote
1
down vote
up vote
1
down vote
you can use this snip of code to filter your results and exclude Folders
var g;
$.ajax(
url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/Lists/GetByTitle('Training Material')/Items",
type: 'GET',
dataType: "json",
headers:
"Accept": "application/json;odata=verbose",
"content-type": "application/json; odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
,
success: function (data)
for (var i = 0; i < data.d.results.length; i++)
if (data.d.results[i].FileSystemObjectType != 1)
,
error: function (request, error)
console.log(JSON.stringify(request));
);
The above code will return all the items of document library including folders. So, to exclude folders, we can use FileSystemObjectType
property to determind whether the current item is folder or file. For more information on FileSystemObjectType, visit This Link
you can use this snip of code to filter your results and exclude Folders
var g;
$.ajax(
url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/Lists/GetByTitle('Training Material')/Items",
type: 'GET',
dataType: "json",
headers:
"Accept": "application/json;odata=verbose",
"content-type": "application/json; odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
,
success: function (data)
for (var i = 0; i < data.d.results.length; i++)
if (data.d.results[i].FileSystemObjectType != 1)
,
error: function (request, error)
console.log(JSON.stringify(request));
);
The above code will return all the items of document library including folders. So, to exclude folders, we can use FileSystemObjectType
property to determind whether the current item is folder or file. For more information on FileSystemObjectType, visit This Link
answered 1 hour ago


Melad Francis
8041614
8041614
add a comment |Â
add a comment |Â
up vote
1
down vote
You have to change the REST URL and point to the document library.
data.Files property will contain only the files and data.Folders will contain the folders.
var RestUrl= _spPageContextInfo.webAbsoluteUrl+ "/_api/Web/GetFolderByServerRelativeUrl('/Shared%20Documents')?$expand=Folders,Files"; //document library name
$.getJSON(RestUrl,function(data,status,xhr)
if(data.Files.length > 0)
var results = data.Files;
);
The above code is tested and works fine.
add a comment |Â
up vote
1
down vote
You have to change the REST URL and point to the document library.
data.Files property will contain only the files and data.Folders will contain the folders.
var RestUrl= _spPageContextInfo.webAbsoluteUrl+ "/_api/Web/GetFolderByServerRelativeUrl('/Shared%20Documents')?$expand=Folders,Files"; //document library name
$.getJSON(RestUrl,function(data,status,xhr)
if(data.Files.length > 0)
var results = data.Files;
);
The above code is tested and works fine.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
You have to change the REST URL and point to the document library.
data.Files property will contain only the files and data.Folders will contain the folders.
var RestUrl= _spPageContextInfo.webAbsoluteUrl+ "/_api/Web/GetFolderByServerRelativeUrl('/Shared%20Documents')?$expand=Folders,Files"; //document library name
$.getJSON(RestUrl,function(data,status,xhr)
if(data.Files.length > 0)
var results = data.Files;
);
The above code is tested and works fine.
You have to change the REST URL and point to the document library.
data.Files property will contain only the files and data.Folders will contain the folders.
var RestUrl= _spPageContextInfo.webAbsoluteUrl+ "/_api/Web/GetFolderByServerRelativeUrl('/Shared%20Documents')?$expand=Folders,Files"; //document library name
$.getJSON(RestUrl,function(data,status,xhr)
if(data.Files.length > 0)
var results = data.Files;
);
The above code is tested and works fine.
edited 1 hour ago
answered 1 hour ago
Sohail Shaikh
1917
1917
add a comment |Â
add a comment |Â
up vote
0
down vote
A few more options actually available:
items?$top=1000&$select=Title,FileLeafRef,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText&$filter=FSObjType eq 0
FSObjType
(display name Item Type
) is a built-in field, values are based on this enumeration
OR
items?$top=1000&$select=Title,FileLeafRef,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText&$filter=startswith(ContentTypeId, '0x0101')
Later approach uses content type and filters out only items which are File-based content type (0x0101
)
add a comment |Â
up vote
0
down vote
A few more options actually available:
items?$top=1000&$select=Title,FileLeafRef,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText&$filter=FSObjType eq 0
FSObjType
(display name Item Type
) is a built-in field, values are based on this enumeration
OR
items?$top=1000&$select=Title,FileLeafRef,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText&$filter=startswith(ContentTypeId, '0x0101')
Later approach uses content type and filters out only items which are File-based content type (0x0101
)
add a comment |Â
up vote
0
down vote
up vote
0
down vote
A few more options actually available:
items?$top=1000&$select=Title,FileLeafRef,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText&$filter=FSObjType eq 0
FSObjType
(display name Item Type
) is a built-in field, values are based on this enumeration
OR
items?$top=1000&$select=Title,FileLeafRef,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText&$filter=startswith(ContentTypeId, '0x0101')
Later approach uses content type and filters out only items which are File-based content type (0x0101
)
A few more options actually available:
items?$top=1000&$select=Title,FileLeafRef,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText&$filter=FSObjType eq 0
FSObjType
(display name Item Type
) is a built-in field, values are based on this enumeration
OR
items?$top=1000&$select=Title,FileLeafRef,FieldValuesAsText/FileRef,FieldValuesAsText/FileRef/Title&$expand=FieldValuesAsText&$filter=startswith(ContentTypeId, '0x0101')
Later approach uses content type and filters out only items which are File-based content type (0x0101
)
answered 18 mins ago
Sergei Sergeev
8,97352240
8,97352240
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsharepoint.stackexchange.com%2fquestions%2f250411%2fexclude-folder-from-results-in-sharepoint-rest-api%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password