Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to: Developer
Use Microsoft Graph file and DriveItem APIs to manage files inside SharePoint Embedded containers.
Complete Create and manage containers first so you have a container ID.
Understand file storage
A SharePoint Embedded container is the storage boundary for your application content.
Each container exposes file content through Microsoft Graph file storage and DriveItem APIs.
Use your application data model to decide which business object owns each container, which folders your app creates, which users or services can read and write, and which file IDs your app stores.
For architecture, see SharePoint Embedded app architecture.
Use Microsoft Graph file storage APIs
Start with these Microsoft Graph references:
Important
Use documented Microsoft Graph DriveItem and file storage APIs. Don't invent SharePoint Embedded-specific file API names.
Prerequisites
Before managing files, make sure:
- Your app can acquire Microsoft Graph tokens.
- The app has
FileStorageContainer.Selectedconsent. - The app has container type permissions for intended operations.
- The target container exists.
- For delegated calls, the user is a member of the container.
- Your app stores the container ID and DriveItem IDs it needs.
Map container IDs to drives
The preview source notes that the Graph preview endpoint uses a driveId, and for SharePoint Embedded the drive ID is the container ID that starts with b!.
In your app:
Store the container ID returned when the container is created.
Use the container ID when calling DriveItem APIs that require a drive identifier.
Store item IDs returned by upload or folder creation operations.
Avoid reconstructing IDs from URLs.
Upload files
Use Microsoft Graph upload patterns for DriveItems.
For small files (up to 250 MB), use the simple upload API documented for DriveItems with a single PUT to the item's content.
For larger files (over 250 MB), use an upload session as documented by Microsoft Graph and send the file in byte-range chunks (for example, 320 KB multiples) until the upload completes.
In your upload flow:
- Validate write access.
- Choose a destination folder in the container.
- Create folders first if the path doesn't exist.
- Upload file bytes with the appropriate Graph method.
- Store the returned DriveItem ID.
- Display file name, size, and status.
Tip
Keep business metadata in your application database, and keep file content in SharePoint Embedded.
Download files
Use Microsoft Graph DriveItem download capabilities for file content.
In your download flow:
- Validate read access.
- Resolve the container ID and DriveItem ID.
- Request the file content or download URL using DriveItem APIs.
- Stream the content to the user or service.
- Handle expiration for short-lived download URLs.
- Log according to your audit requirements.
Create folders
Use DriveItem folder creation APIs to organize content.
Create folders for predictable content structure, workflow stages, related uploads, and stable parent items for Office launch URLs.
When creating folders:
- Check whether the folder exists.
- Create only the missing path segment.
- Store the folder DriveItem ID if needed.
- Apply naming rules consistently.
Update file content
Use Microsoft Graph DriveItem update or upload session patterns to replace content.
Before replacing content:
- Confirm write permission.
- Read current metadata if concurrency checks are needed.
- Preserve the DriveItem ID where supported.
- Update your app metadata after Graph succeeds.
Office files stored in SharePoint Embedded have versioning enabled automatically for Word, Excel, and PowerPoint files.
See Open Office files from your app for Office behavior.
Rename or move items
Use documented DriveItem update and move operations where supported.
A safe flow should read the current DriveItem, confirm the destination folder, apply the operation, refresh stored path or display name, and keep the DriveItem ID as the durable reference when possible.
Delete files
Use delete operations when a file should no longer appear in the active content experience.
Before deleting:
- Confirm user intent.
- Confirm write or delete permission.
- Decide whether your app needs soft delete.
- Update app state only after Graph returns success.
Restore files
Use Microsoft Graph and SharePoint file restore capabilities documented for DriveItems and the service experience.
A restore flow should identify the deleted item or version, confirm permission, perform the restore, refresh the item list, and communicate the restored location.
Note
recycleBinItem: restore supports driveItemId as an alternate key (October 2025). If you know the ID of the original driveItem, you can restore the corresponding recycleBinItem directly without first enumerating the recycle bin.
Note
For exact file operation request and response details, use Microsoft Graph DriveItem documentation.
Connect to Office and preview experiences
After upload, add richer experiences:
- Open Office files from your app for Word, Excel, and PowerPoint launch behavior.
- Preview files in your app for browser previews.
- Search containers and files for discovery.
Validate file operations
Create a smoke test:
- Create a test container.
- Create a folder.
- Upload a file.
- Read returned DriveItem metadata.
- Download the file.
- Replace the content.
- Rename the file.
- Delete the file.
- Restore it if supported.
- Clean up the test container.
Troubleshoot file operations
| Symptom | Check |
|---|---|
| Upload fails | WriteContent permission and user Writer role. |
| Download fails | ReadContent permission and user Reader role. |
| Folder create fails | Parent folder ID and write permissions. |
| Preview fails | File type support and preview URL generation. |
| Office launch opens wrong mode | Launch URL action parameter or Office URI scheme. |
| Access differs by user | Delegated access intersects app permissions with membership. |
Next steps
Enable Office launch experiences in Open Office files from your app.