Overview
In the previous post we’ve already discussed how to perform CRUD operations by sending HTTPS requests to SharePoint RESTful web services in PoweShell. The Invoke-RestSPO function was introduced for that purpose since Invoke-RestMethod cmdlet does not support claims based authentication and it makes this cmdlet impossible to use in O365 and SharePoint Online scenarios.
This time I am going to demonstrate how to perform basic create, read, update, and delete (CRUD) operations on folders and files with the SharePoint 2013 REST interface using Invoke-RestSPO function.
Working with folders
Folder resource: represents a folder on a SharePoint Web site
Endpoint URI: http://<site url>/_api/web/getfolderbyserverrelativeurl(‘/<folder name>‘)
Supported HTTP methods: GET | POST | DELETE | MERGE | PUT
The following examples demonstrates how to perform basic CRUD operations with Folder resource.
Working with files
Folder resource: represents a file in a SharePoint Web site that can be a Web Part Page, an item in a document library, or a file in a folder.
Endpoint URI: http://<site url>/_api/web/getfilebyserverrelativeurl(‘/<folder name>/<file name>‘)
Supported HTTP methods: GET | DELETE | POST (File resource)
The following examples demonstrates how to perform basic operations with File resource including:
- upload file into SharePoint
- download file from a SharePoint
Summary
To summarize, it was demonstrates how to perform basic operations with files and folders, in particular how to download and upload files via REST. For that purpose we utilized Invoke-RestSPO function that is intended for sending HTTPS requests to O365/SharePoint Online REST service.
References
- Consuming the SharePoint 2013 REST API from PowerShell
- Files and folders REST API reference
- Working with folders and files with REST