0

I have a document library which contains folders and document sets. I am trying to decide which to use for this case, is there a better option??

So I have the library known as 'TestTracking', which contains folders (or document sets depending which is the best option). I wish there was a way to have different columns for the files that are within the document sets/folders as it gets confusing having to mess with the content type.

Each folder in the library is a name, nested in that folder are files that have a retention date, start date, file type, and name of the file. There is a name value for both the folder as well as the file inside the folder, and when I use REST API, I cannot seem to find that value anywhere in my response. How can I filter/query/expand the results. This is a bit more confusing than normal list operations.

Here is my url for my AJAX call:

var libraryUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('TestTracker')/items?select=Files$expand=Children";

What I am trying to access. In the parent(TestTracker Library), each folder has three columns showing relevant to that column. Name (default), Team, and OnBoardingDate. Within that folder, what I need to grab is the Name (default), Type (choice column for what the file is), and isRetained, a calculated column based off the OnBoardingDate.

2
  • 1
    Are you trying to fetch SharePoint default "Name" field using REST API? Or is this the custom column you created in library? Commented Aug 30, 2021 at 16:33
  • @GaneshSanap the default one. I will list what my fields are that I am trying to access in OP
    – BeerusDev
    Commented Aug 30, 2021 at 16:35

1 Answer 1

1

Try using REST endpoint like below:

var libraryUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('TestTracker')/items?$select=FileLeafRef,File_x0020_Type,isRetained";

Assuming isRetained is correct internal name of your column. You can get the exact internal name of your column by following this article: How to find the Internal name of columns in SharePoint Online?

In above query:

  • FileLeafRef: returns file name with example (SharePoint default column)
  • File_x0020_Type: returns file type (SharePoint default column)

Example XML response:

<m:properties>
    <d:FileLeafRef>TestDocument.docx</d:FileLeafRef>
    <d:File_x0020_Type>docx</d:File_x0020_Type>
</m:properties>

Update from comments:

To get only files & exclude folders, add filter on FSObjType property like:

var libraryUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('TestTracker')/items?$select=FileLeafRef,File_x0020_Type,isRetained,FSObjType&$filter=FSObjType eq 0"
4
  • My data type is JSON, and FileLeafRef doesn't return anything upon completion of the request. How come if I have one folder with one file in it, the call returns two objects in the response instead of one nested one? Gonna make it a lot harder to manipulate
    – BeerusDev
    Commented Aug 30, 2021 at 17:12
  • XML response was just for example. You will get the same response in JSON as well. And yes, it does return two objects - 1 for folder & 1 for a file. To get only files / folders, you can add filter on the FSObjType property as given in updated answer. Commented Aug 30, 2021 at 17:32
  • gotcha. How can I pull the actual file through the REST API? I try to do the following /items?$expand=Employee&$select=Team,Attachments,AttachmentFiles,Title,Certification,OnboardingDate,IsRetained,Employee/Title and I get the error that The field or property 'Attachments' does not exist.
    – BeerusDev
    Commented Aug 30, 2021 at 18:57
  • Attachments column does not exist in document library. So, try using endpoint like: /_api/web/lists/getbytitle('TestTracker')/items?$select=FileLeafRef,File_x0020_Type,isRetained,FSObjType,File&$expand=File&$filter=FSObjType eq 0 Commented Aug 31, 2021 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.