0

Similar to this (Upload multiple files using rest api) I want to upload files to an existing Docset. I am using the pure REST API as I am on Java.

I asked myself, how to control where the uploaded file should go - currently it's going to the "root" of my list.

Sorry if my wording is maybe misleading, but I am not a Sharepoint user or developer - I just have to connect to it with another app.

The upload URL I am using looks like this:

_api/web/getfolderbyserverrelativeurl(''{0}'')/files/add(overwrite=true,url=''{2}'')?$expand=ListItemAllFields

Where it oviously starts with my host and website etc. and the placeholders being replaced with

  • the server's relative URL I got before after I created the DocSet (0)
  • the file name of the uploaded element (2)

I thought I can control the target DocSet by adding to the URL right after (0) OR before the /files part - both lead to an error that says that this is an unknown resource.

Maybe there is a different approach to control the target DocSet?

1 Answer 1

0

A Document Set is, in essence, a folder, so the value you need for getfolderbyserverrelativeurl is the server relative URL to the document set itself.

If your document set is in the root of a document library, that would be something like

'/sites/YourSite/Your Library/Your Doc Set'

That all needs to be in your {0} replacement value. You don't need to add anything else to the URL.

5
  • When I do so, it looks like this: _api/web/getfolderbyserverrelativeurl('/websites/A0000023/TaskItLibrary/ne+mail+mit+zeug+und+so')/files/add(overwrite=true,url='OBUE-C7WHED_f.eml')?$expand=ListItemAllFields' - I have to encode the DocSet's name, otherwise I get "illegal characters" exception. With this URL I also get an error which says: System.IO.DirectoryNotFoundException - File not found Commented Oct 19, 2021 at 14:02
  • If you know the list item ID of the Doc Set's list item, you can get what SharePoint expects the relative URL to be by getting /_api/web/list/getbytitle('Your Library')/items(itemID)/Folder?$select=ServerRelativeUrl, that might help? Commented Oct 19, 2021 at 14:38
  • Yes, it looks exactly like I commented before: /websites/A0000023/TaskItLibrary/ne+mail+mit+zeug+und+so but this does not work. Commented Oct 19, 2021 at 15:19
  • Sorry, not sure what to tell you then. Commented Oct 19, 2021 at 15:36
  • My problem was the wrong URL enconding, so it seems that you cannot use a "+" as a space instead of "%20" - so I had to change the encoding... Commented Oct 19, 2021 at 15: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.