1
1
---
2
2
title : Working with folders and files with REST
3
3
description : Perform basic create, read, update, and delete (CRUD) operations on folders and files with the SharePoint REST interface.
4
- ms.date : 06/07 /2022
4
+ ms.date : 08/18 /2022
5
5
ms.prod : sharepoint
6
6
ms.localizationpriority : high
7
7
---
@@ -117,7 +117,7 @@ Authorization: "Bearer " + accessToken
117
117
You can also ** retrieve a file when you know its URL** , as in the following example.
118
118
119
119
``` http
120
- GET https://{site_url}/_api/web/GetFileByServerRelativeUrl('/Folder Name/{file_name})/$value
120
+ GET https://{site_url}/_api/web/GetFileByServerRelativeUrl('/Folder Name/{file_name}' )/$value
121
121
Authorization: "Bearer " + accessToken
122
122
```
123
123
@@ -201,7 +201,7 @@ The following example shows how to **update a file by using the PUT method**.
201
201
> ** PUT** is the only method that you can use to update a file. The ** MERGE** method is not allowed.
202
202
203
203
``` http
204
- POST https://{site_url}/_api/web/GetFileByServerRelativeUrl('/Folder Name/{file_name})/$value
204
+ POST https://{site_url}/_api/web/GetFileByServerRelativeUrl('/Folder Name/{file_name}' )/$value
205
205
Authorization: "Bearer " + accessToken
206
206
Content-Length: {length of request body as integer}
207
207
X-HTTP-Method: "PUT"
@@ -270,11 +270,13 @@ function uploadFileBinary() {
270
270
else {
271
271
requestExecutor = new SP.RequestExecutor (document .getElementById (" TxtWebUrl" ).value );
272
272
}
273
+
273
274
var body = " " ;
274
275
for (var i = 0 ; i < 1000 ; i++ ) {
275
276
var ch = i % 256 ;
276
277
body = body + String .fromCharCode (ch);
277
278
}
279
+
278
280
var info = {
279
281
url: " _api/web/lists/getByTitle('Shared Documents')/RootFolder/Files/Add(url='a.dat', overwrite=true)" ,
280
282
method: " POST" ,
@@ -284,6 +286,7 @@ function uploadFileBinary() {
284
286
error: fail,
285
287
state: " Update"
286
288
};
289
+
287
290
requestExecutor .executeAsync (info);
288
291
}
289
292
@@ -294,7 +297,7 @@ function uploadFileBinary() {
294
297
The following example shows how to ** retrieve all of the files that are attached to a list item** .
295
298
296
299
``` http
297
- GET https://{site_url}/_api/web/lists/getbytitle('{list_title}')/items({item+id })/AttachmentFiles/
300
+ GET https://{site_url}/_api/web/lists/getbytitle('{list_title}')/items({item_id })/AttachmentFiles/
298
301
Authorization: "Bearer " + accessToken
299
302
Accept: "application/json;odata=verbose"
300
303
```
0 commit comments