You see error 0x80070021 when trying to save an email attachment or open a file from Outlook. This error means a file is locked by another process. The conflict often happens with files stored in OneDrive or SharePoint. This article explains how to resolve the lock and prevent the error.
Key Takeaways: Resolving Outlook File Lock Errors
- Close the file in all other apps: The most common cause is having the file open in Word, Excel, or another program.
- Pause OneDrive sync: Temporarily stopping sync releases the file lock held by the OneDrive process.
- Clear the Windows thumbnail cache: Windows File Explorer can lock files while generating previews, which this step fixes.
Why Outlook Shows Error 0x80070021 with OneDrive Files
Error code 0x80070021 is a system-level sharing violation. It occurs when Windows blocks access to a file because it is already in use. For Outlook users, this typically happens with cloud-synced files from OneDrive or SharePoint.
The OneDrive sync engine (OneDrive.exe) frequently holds a lock on files to upload or download changes. Other Microsoft 365 apps like Word or Excel also maintain locks for auto-save. If you try to save an Outlook attachment with the same name to a synced folder, or open a file recently edited elsewhere, the conflict triggers the error.
How File Locks Work in Windows
Windows uses file locks to prevent data corruption when multiple programs try to write to the same file. The lock is usually released when the program closes the file. However, cloud sync services like OneDrive can keep a file handle open longer than expected, especially during slow uploads.
Steps to Resolve the OneDrive File Lock Error
Follow these steps in order. Start with the simplest solution first.
- Close all other applications
First, close any program that might be using the file. This includes Microsoft Word, Excel, PowerPoint, Adobe Reader, and any photo editors. Save your work in those apps and exit them completely. Check your system tray for apps running in the background. - Pause OneDrive synchronization
Click the OneDrive cloud icon in your system tray. Select Help & Settings > Pause syncing. Choose a duration like 2 hours. This action tells OneDrive to release its lock on local files, allowing Outlook to access them. - Clear the Windows thumbnail cache
Open File Explorer and go to the folder containing the locked file. Switch the view to Details or List view, not Large Icons or any preview view. Then, open the Disk Cleanup tool, select Thumbnails, and clean them. This stops File Explorer from locking files to generate previews. - Restart your computer
A full restart clears all temporary file handles and stops background processes. This is a reliable way to release stubborn locks held by system services. After restarting, try the Outlook operation again before opening other apps. - Check for open file handles with Process Explorer
If the error persists, download Process Explorer from Microsoft’s website. Run it as an administrator. Press Ctrl+F and search for the name of the locked file. The search results will show which process has a handle open. You can close that handle directly from the tool.
If the Error Keeps Happening After the Main Fix
Outlook still cannot save an attachment to OneDrive
Save the attachment to a local folder not synced by OneDrive, such as your Desktop or Documents folder. Wait a few moments, then manually move the file into your OneDrive folder. This bypasses the direct save conflict.
OneDrive shows Sync Pending or Sync Error status
A stuck file in OneDrive can cause persistent locks. Open OneDrive settings via the system tray icon. Go to the Sync and backup tab and click View sync problems. Resolve any listed errors. You may need to rename the problematic file locally to break the sync loop.
File opens as read-only from the Outlook link
This indicates the file is checked out in SharePoint or locked for editing by another user. Open your SharePoint site in a browser, navigate to the document library, and check if the file requires check-in. Alternatively, save a copy of the file with a different name for your edits.
Preventing Error 0x80070021: Workflow Comparison
| Item | Risky Workflow (Causes Error) | Safe Workflow (Prevents Error) |
|---|---|---|
| Saving Attachments | Directly save from Outlook to an active OneDrive sync folder | Save to a local folder first, then drag into OneDrive |
| Editing Shared Files | Opening a file directly from an Outlook email link while it’s open on another device | Check file status in SharePoint first or use Open as Copy |
| OneDrive Sync Settings | Files On-Demand enabled with all files set to online-only | Keep frequently used files set to Always keep on this device |
| Outlook Configuration | Default save location set to a synced OneDrive folder | Set default save location to a local, non-synced path |
You can now save attachments and open files without the lock conflict error. The key is managing how OneDrive interacts with other apps. For a related setting, configure Outlook’s attachment preview to open files in Protected View. This advanced tip prevents automatic locks by opening files in a read-only state first, giving you control over when to enable editing.