To copy documents across site collections in provider hosted app, we need to perform the following steps:
- Provide appropriate permissions to app
- Create client context for the source location
- Downloading document stream from source
- Create client context for the destination
- Uploading document to destination (This step is same as mentined in my previous post)
The approach I am going to display will also help if you want to create another site collection context from the existing one.
For the above scenario, please note the following points:
- App should have minimum “Write” permission on “Tenant” for the code to work as we are moving document from one site collection to another.
- I have used app-only policy. This is used as user might not have write permission on the whole tenant. The only downside is, in “Created By” field, instead of user name, it shows “SharePoint App”. I created a custom column to save actual user name.
Hope this helps. Happy coding!!