質問

In server side object model, we have Recycle method to send the deleted list item attachment to the recycle bin.

With this method, users can always restore deleted attachment from the recycle bin.

This recycle method is available in REST for "list item", but I could not find any reference for "list item attachment".

Is there an equivalent method in JavaScript Object Model or REST API for attachment in SharePoint on-premises?

役に立ちましたか?

解決

You need to append recycleObject to the attachment endpoint to send them to the recycle bin.

The REST endpoint would be as:

.../getItemById(20)/AttachmentFiles/getByFileName('test.docx')/RecycleObject

Using jQuery, you can do that as:

var attachEndPoint = _spPageContextInfo.webAbsoluteUrl + 
"/_api/lists/getByTitle('Test')/
getItemById(20)/AttachmentFiles/getByFileName('test.docx')/RecycleObject";

$.ajax({
  url:  attachEndPoint,
  method: 'DELETE',
  headers: {
    'X-RequestDigest': $('#__REQUESTDIGEST').val()
  },
  success: function(data){
        console.log(data);
        console.log("success");
  },
  error: function(data){
        console.log(data);
        console.log("error")
  }
});

If you are using PnP JS, then you can use it :

import pnp from "sp-pnp-js";

let item = pnp.sp.web.lists.getByTitle("Test").items.getById(1);

item.attachmentFiles.getByName("test.docx").recycle().then(v => {

    console.log(v);
});

If you want to send multiple attachments to recycle bin, then you can use it as:

const list = pnp.sp.web.lists.getByTitle("Test");

list.items.getById(1).attachmentFiles.recycleMultiple("test.docx","test2.pdf").then(r => {
    console.log(r);
});
ライセンス: CC-BY-SA帰属
所属していません sharepoint.stackexchange
scroll top