{"id":6489,"date":"2021-06-22T02:59:13","date_gmt":"2021-06-22T09:59:13","guid":{"rendered":"https:\/\/officedevblogs.wpengine.com\/?p=6489"},"modified":"2023-08-04T08:34:08","modified_gmt":"2023-08-04T15:34:08","slug":"improved-api-support-for-working-with-files-in-the-sharepoint-recycle-bin","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/improved-api-support-for-working-with-files-in-the-sharepoint-recycle-bin\/","title":{"rendered":"Improved API support for working with files in the SharePoint recycle bin"},"content":{"rendered":"<p>We\u2019re rolling out some improvements for working with files in the SharePoint recycle bin. Once these changes are active, files and folders that are recycled will be placed into new \u201crecycle bin libraries\u201d. Contents of recycled files in these new libraries can be accessed by APIs with the use of a special request header.<\/p>\n<p><em>[Updated 4th of August 2023] &#8211; This feature is has been rolled back and is not currently enabled in production.<\/em><\/p>\n<p>These new recycle bin libraries will have some special behaviors:<\/p>\n<ul>\n<li>By default, they will be hidden from APIs which enumerate or otherwise interact with lists or libraries<\/li>\n<li>By default, files and folders within them will not be accessible by the UI or APIs<\/li>\n<li>They will not have forms or views<\/li>\n<li>They are implicitly created when files or folders are recycled and cannot be created directly<\/li>\n<li>They mirror the schema and settings of the source library from which files and folders are recycled<\/li>\n<\/ul>\n<h3><strong>Accessing Recycled Files with a new x-RecycleBinContentAware\u00a0Header<\/strong><\/h3>\n<p>Recycle bin libraries, and the items within them, can be accessed by including the following request header:<\/p>\n<pre class=\"\">  x-RecycleBinContentAware: True<\/pre>\n<p>Providing this header when setting up the <em>Context<\/em> of an <em>SPSite <\/em>or <em>SPWeb<\/em> will:<\/p>\n<ul>\n<li>Allow the <em>SPList<\/em> object for recycle bin libraries to be enumerated<\/li>\n<li>Allow the <em>SPFile<\/em>, <em>SPFolder<\/em>, and <em>SPListItem<\/em> objects within recycle bin libraries to be enumerated<\/li>\n<li>Treat the SPSite, and associated SPWeb, as read-only in the scope of the request for all content<\/li>\n<li>Append a query parameter to pre-authenticated URLs on recycled files that enable content download<\/li>\n<\/ul>\n<h3><b><span lang=\"EN-US\" style=\"color: windowtext;\">New ChangeLog Behavior<\/span><\/b><\/h3>\n<p>Because these new libraries are hidden from the UI and APIs by default, these changes should not generally have any impact on end-users or applications with one exception; change log operations for files and folders moving to and from the SharePoint recycle bin will look different. Applications that consume operations from the change log, by using the <a href=\"https:\/\/nam06.safelinks.protection.outlook.com\/?url=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fapi%2Fmicrosoft.sharepoint.client.site.getchanges%3Fview%3Dsharepoint-csom&amp;data=04%7C01%7Cmawin%40microsoft.com%7C6fb2e1aaa071495a105408d8ea3d9ae1%7C72f988bf86f141af91ab2d7cd011db47%7C0%7C0%7C637516897604518700%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=9N4SsSfuOSThqzLXUgntIRo9ffpasGC9klFwlPfQzO4%3D&amp;reserved=0\">Site.GetChanges<\/a> and <a href=\"https:\/\/nam06.safelinks.protection.outlook.com\/?url=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fapi%2Fmicrosoft.sharepoint.client.web.getchanges%3Fview%3Dsharepoint-csom&amp;data=04%7C01%7Cmawin%40microsoft.com%7C6fb2e1aaa071495a105408d8ea3d9ae1%7C72f988bf86f141af91ab2d7cd011db47%7C0%7C0%7C637516897604528656%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=TCoXz71%2BQ8it2sxx6k%2F5%2B8tYtA3SjinFOrj2YLnTF9s%3D&amp;reserved=0\">Web.GetChanges<\/a> APIs for example, may need to be updated to understand this new behavior.<\/p>\n<p>When a file or folder is <strong>recycled<\/strong>, the new behavior will be to:<\/p>\n<ol>\n<li>Ensure a recycle bin library exists corresponding to the library the file\/folder is in.<\/li>\n<li>Create a folder in the recycle bin library to correspond to the recycle bin item.<\/li>\n<li>Break inheritance on the recycle bin item folder and copy the permissions to match the effective permissions of the file\/folder being recycled.<\/li>\n<li>Move the recycled file\/folder to the new folder.<\/li>\n<\/ol>\n<p>When a file or folder is <strong>restored<\/strong>, the new behavior will be to:<\/p>\n<ol>\n<li>Move the recycled file\/folder from the recycle bin item folder back to its original location.<\/li>\n<li>Delete the folder<\/li>\n<\/ol>\n<p>When a file or folder is <strong>purged<\/strong>, the new behavior will be to:<\/p>\n<ol>\n<li>Delete the recycle bin item folder (including its contents)<\/li>\n<\/ol>\n<p>To support this new behavior, two new properties called <em>MoveWasForRecyle<\/em> and <em>MoveWasForRestore<\/em> will be added to change log operations to help distinguish the scenarios mentioned above.<\/p>\n<p>Here\u2019s an example of what these updated operations might look like for each of the above scenarios.<\/p>\n<p><strong>File operation &#8211; Recycle a file\/folder<\/strong><\/p>\n<p>Example change log operations (BEFORE)<\/p>\n<pre class=\"\"><em>ChangeType: Delete<\/em>\r\n<em>Id: 1<\/em>\r\n<em>UniqueId: 3275877d-229e-4767-bfee-83020b81826d<\/em>\r\n<em>BeforeId: 1<\/em>\r\n<em>AfterId: 1<\/em>\r\n<em>ListId: 42782c92-928b-463e-bc3a-85b315c2eab7<\/em>\r\n<em>BeforeListId: 42782c92-928b-463e-bc3a-85b315c2eab7<\/em>\r\n<em>AfterListId: 42782c92-928b-463e-bc3a-85b315c2eab7<\/em>\r\n<em>MoveWasForRecycle: False<\/em>\r\n<em>MoveWasForRestore: False<\/em>\r\n<em>ObjectType: Item<\/em>\r\n<em>Token: 1;1;090d6057-a037-4c7f-9e38-40ae9bc9a820;637480701247470000;4493<\/em><\/pre>\n<p>Example change log operations (AFTER)<\/p>\n<pre class=\"\">ChangeType: Add\r\nId: 2\r\nUniqueId: 525dec27-ba55-4bde-9fe0-555369d9636e\r\nBeforeId: 2\r\nAfterId: 2\r\nListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nBeforeListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nAfterListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nMoveWasForRecycle: False\r\nMoveWasForRestore: False\r\nObjectType: Item\r\nToken: 1;1;090d6057-a037-4c7f-9e38-40ae9bc9a820;637480701259930000;4515\r\n\r\nChangeType: AssignmentAdd\r\nId: 2\r\nUniqueId: 525dec27-ba55-4bde-9fe0-555369d9636e\r\nBeforeId: 2\r\nAfterId: 2\r\nListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nBeforeListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nAfterListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nMoveWasForRecycle: False\r\nMoveWasForRestore: False\r\nObjectType: Item\r\nToken: 1;1;090d6057-a037-4c7f-9e38-40ae9bc9a820;637480701259930000;4516\r\n\r\nChangeType: ScopeAdd\r\nId: 2\r\nUniqueId: 525dec27-ba55-4bde-9fe0-555369d9636e\r\nBeforeId: 2\r\nAfterId: 2\r\nListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nBeforeListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nAfterListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nMoveWasForRecycle: False\r\nMoveWasForRestore: False\r\nObjectType: Item\r\nToken: 1;1;090d6057-a037-4c7f-9e38-40ae9bc9a820;637480701259930000;4517\r\n\r\nChangeType: MoveAway\r\nId: 1\r\nUniqueId: 10e02ee2-b76f-46ce-b084-9030607d92da\r\nBeforeId: 1\r\nAfterId: 1\r\nListId: 14d4eefa-1c3c-491e-8b5b-14b993f35bde\r\nBeforeListId: 14d4eefa-1c3c-491e-8b5b-14b993f35bde\r\nAfterListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nMoveWasForRecycle: True\r\nMoveWasForRestore: False\r\nObjectType: Item\r\nToken: 1;1;090d6057-a037-4c7f-9e38-40ae9bc9a820;637480701260000000;4518\r\n\r\nChangeType: MoveInto\r\nId: 1\r\nUniqueId: 10e02ee2-b76f-46ce-b084-9030607d92da\r\nBeforeId: 1\r\nAfterId: 1\r\nListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nBeforeListId: 14d4eefa-1c3c-491e-8b5b-14b993f35bde\r\nAfterListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nMoveWasForRecycle: True\r\nMoveWasForRestore: False\r\nObjectType: Item\r\nToken: 1;1;090d6057-a037-4c7f-9e38-40ae9bc9a820;637480701260000000;4519<\/pre>\n<p><strong>File operation &#8211; Restore a file\/folder<\/strong><\/p>\n<p>Example change log operations (BEFORE)<\/p>\n<pre class=\"\">ChangeType: Restore\r\nId: 1\r\nUniqueId: 3275877d-229e-4767-bfee-83020b81826d\r\nBeforeId: 1\r\nAfterId: 1\r\nListId: 42782c92-928b-463e-bc3a-85b315c2eab7\r\nBeforeListId: 42782c92-928b-463e-bc3a-85b315c2eab7\r\nAfterListId: 42782c92-928b-463e-bc3a-85b315c2eab7\r\nMoveWasForRecycle: False\r\nMoveWasForRestore: False\r\nObjectType: Item\r\nToken: 1;1;090d6057-a037-4c7f-9e38-40ae9bc9a820;637480701247700000;4494<\/pre>\n<p>Example change log operations (AFTER)<\/p>\n<pre class=\"\">ChangeType: MoveAway\r\nId: 1\r\nUniqueId: 10e02ee2-b76f-46ce-b084-9030607d92da\r\nBeforeId: 1\r\nAfterId: 1\r\nListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nBeforeListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nAfterListId: 14d4eefa-1c3c-491e-8b5b-14b993f35bde\r\nMoveWasForRecycle: False\r\nMoveWasForRestore: True\r\nObjectType: Item\r\nToken: 1;1;090d6057-a037-4c7f-9e38-40ae9bc9a820;637480701260200000;4520\r\n\r\nChangeType: MoveInto\r\nId: 1\r\nUniqueId: 10e02ee2-b76f-46ce-b084-9030607d92da\r\nBeforeId: 1\r\nAfterId: 1\r\nListId: 14d4eefa-1c3c-491e-8b5b-14b993f35bde\r\nBeforeListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nAfterListId: 14d4eefa-1c3c-491e-8b5b-14b993f35bde\r\nMoveWasForRecycle: False\r\nMoveWasForRestore: True\r\nObjectType: Item\r\nToken: 1;1;090d6057-a037-4c7f-9e38-40ae9bc9a820;637480701260200000;4521\r\n\r\nChangeType: Delete\r\nId: 2\r\nUniqueId: 525dec27-ba55-4bde-9fe0-555369d9636e\r\nBeforeId: 2\r\nAfterId: 2\r\nListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nBeforeListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nAfterListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nMoveWasForRecycle: False\r\nMoveWasForRestore: False\r\nObjectType: Item\r\nToken: 1;1;090d6057-a037-4c7f-9e38-40ae9bc9a820;637480701260230000;4522<\/pre>\n<p><strong>File operation &#8211; Purge a file\/folder<\/strong><\/p>\n<p>Example change log operations (BEFORE)<\/p>\n<pre class=\"\">ChangeType: Delete\r\nId: 1\r\nUniqueId: 3275877d-229e-4767-bfee-83020b81826d\r\nBeforeId: 1\r\nAfterId: 1\r\nListId: 42782c92-928b-463e-bc3a-85b315c2eab7\r\nBeforeListId: 42782c92-928b-463e-bc3a-85b315c2eab7\r\nAfterListId: 42782c92-928b-463e-bc3a-85b315c2eab7\r\nMoveWasForRecycle: False\r\nMoveWasForRestore: False\r\nObjectType: Item\r\nToken: 1;1;090d6057-a037-4c7f-9e38-40ae9bc9a820;637480701251170000;4495\r\n<\/pre>\n<p>Example change log operations (AFTER)<\/p>\n<pre class=\"\">ChangeType: Delete\r\nId: 3\r\nUniqueId: be147871-1f43-497f-8235-4b247844cc1a\r\nBeforeId: 3\r\nAfterId: 3\r\nListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nBeforeListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nAfterListId: d2812400-908e-4236-b2ec-ded5598ae029\r\nMoveWasForRecycle: False\r\nMoveWasForRestore: False\r\nObjectType: Item\r\nToken: 1;1;090d6057-a037-4c7f-9e38-40ae9bc9a820;637480701263770000;4528<\/pre>\n<p><em>\u201cSharing is caring\u201d<\/em><\/p>\n<hr class=\"wp-block-separator\" \/>\n<p class=\"\"><em>SharePoint Team, Microsoft \u2013 22nd of June 2021<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We\u2019re rolling out some improvements for working with files in the SharePoint recycle bin. Once these changes are active, files and folders that are recycled will be placed into new \u201crecycle bin libraries\u201d. Contents of recycled files in these new libraries can be accessed by APIs with the use of a special request header.<\/p>\n","protected":false},"author":69078,"featured_media":25159,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[],"class_list":["post-6489","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sharepoint-framework"],"acf":[],"blog_post_summary":"<p>We\u2019re rolling out some improvements for working with files in the SharePoint recycle bin. Once these changes are active, files and folders that are recycled will be placed into new \u201crecycle bin libraries\u201d. Contents of recycled files in these new libraries can be accessed by APIs with the use of a special request header.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/6489","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/users\/69078"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/comments?post=6489"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/6489\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media\/25159"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media?parent=6489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/categories?post=6489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/tags?post=6489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}