Changes who can view or edit a file or folder.
class DriveApp method .setSharing()
DriveApp is the Apps Script service.
.setSharing() is the method name you will see after a dot in your code.
What it does
Why it's used
- Share a new report with the client as soon as it is generated.
- Lock down or open up files based on a status column.
Common errors
- Forgetting parentheses on setSharing. Write DriveApp.setSharing(), not DriveApp.setSharing or setSharing by itself.
- Skipping dots between chained calls. Each step needs a dot, like DriveApp.getFileById(id).setSharing().
- Adding spaces where they do not belong. Write DriveApp.setSharing(), not DriveApp .setSharing(), DriveApp.setSharing (), or DriveApp . setSharing().
- Wrong capitalization. Use DriveApp and setSharing, not driveapp or setsharing.
Explore
Related methods
-
.addFile()
Moves a file into a folder.
-
.makeCopy()
Creates a duplicate of a file in Drive.
-
.createFolder()
Creates a new folder in Drive.
-
.removeFile()
Removes a file from a folder without deleting it.
-
.createFile()
Creates a new file in Drive from a name and content.
More Apps Script
Better Sheets tutorials
No tagged tutorials yet. Fetch Apps Script from the harvest table and this page fills automatically.
Related blog posts
Written guides about DriveApp.setSharing().
What's Better Than Google Sheets?
Nothing is better than Google Sheets. You just need to learn more about the unlimited power of Google Sheets. Functions, Formulas, Apps Script and more.
Read post →Automatic Weekly Backup of Google Sheets
How can we create backups of Google sheets every week or every day or every month?
Read post →How to reference a different Google Spreadsheet in Apps Script?
Transferring Data Between Cells in Different Spreadsheets
Read post →