Home > Forum > Actions > Delete one or multiple documents from a SharePoint library

Delete one or multiple documents from a SharePoint library
0

Hi,
We have a client that uses sharepoint to work with documents, for contracts. There is an item list that is used to manage these documents (so far, only upload and download) and they would like to also be able to delete some of the already uploaded documents. There is a main folder for each contract and there are a couple of subfolders for attachments, depending on when they where added.

As far as i understand, i will need to use the action 'Delete a list element'. I see that i can either give it an ID or use a CAML query (first time user here; just started reading about it).
I most definetely need to use the CAML query since there can be more than one document that needs deleting but i am also curios about that ID.

Where can i get that ID from? I tried testing with the Document ID found in SharePint, at info, but got an error ('Cannot convert "{0}" to correct (integer) value of deleted element ID'). If i use 1 it gives back 'There is no Web named "/sites/contracte/Documents/2024/Contract_1/_vti_bin/sites.asmx"'.
Does the CAML query support finding more documents if they are in different folders/subfolders as long as it does not go further back in the List address?
Does the List address need to be all the way to the folder where the documents are or can i stop at the contracts folder?

I would like to make this as dynamic as possible since there is a high chance for other subfolders to appear.
I found some discussions on the forum and will go through these, as well as read more about CAML. Any info and further reading materials will be appreciated.

*the version is 2021.1.3.205, standalone
Thanks in advance,
George

MVP

Hi George,

I'm not a sharepoint expert, I have this comfort that didn't had to work with it, although after doing some research on microsoft side documentation it looks like filles/folders and lists are managed by different API endpoints:
* https://{site_url}/_api/web/GetFileByServerRelativeUrl('/Folder Name/{file_name}') - This is for files/folders
* https://{site_url}/_api/web/lists/GetByTitle('Test')/items({item_id}) - This is for lists

I would assume, that action which is called 'Delete a list element' will work with lists, and use second endpoint - so it's not handling files/folders scenario - there is no some switch to change it.

You could try to make this case work with 'Invoke REST Web service' action, a little bit more work but should be doable (if i remember correctly Daniel from forum done something like that)

Sources:
* https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest
* https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-lists-and-list-items-with-rest

Hi, I believe id is integer number in sharepoint library. It starts with 1. On attached picture you are showing document id Value. You should enable id in the view to test this.

When creating element in a list you can write back id to webcon form. Unfotrunatley webcon does not support this on a library. The reason for this is unknown to me.


Best regards,

Aleš