Recover Deleted Files Visual Studio Not Recycle Bin
If you deleted a file in Visual Studio and it is not in the Recycle Bin, you can often recover it from the Local History feature (for files in a solution) or from the project’s source control (if you use Git or TFVC). This article explains the exact steps for each method, plus what to do if those fail.
Why Deleted Files Skip the Recycle Bin in Visual Studio
When you delete a file from within Visual Studio (right-click → Delete, or press Delete on a selected item), the IDE does not send the file to the Windows Recycle Bin. Instead, it removes the file from disk immediately. This is by design—Visual Studio treats file deletion as a project operation, not a shell operation. The same applies when you delete a file in Solution Explorer and confirm the prompt. Because the file is gone from the filesystem, the Recycle Bin never sees it.
This catches many developers off guard. If you delete a file in File Explorer, it goes to the Recycle Bin. In Visual Studio, it does not. The only exceptions are if you use a third-party add-in that overrides the default behavior, or if you delete a file that is under source control—in that case, the source control system may keep a copy.
Method 1: Use Local History (Built-in, No Add-ins)
Visual Studio has a built-in feature called Local History that automatically saves snapshots of files in a solution. It is enabled by default for projects that are not under source control, and it can also work for source-controlled projects if you have the setting turned on.
- Open the solution that contained the deleted file.
- In Solution Explorer, right-click the project or folder where the file used to be.
- Select Compare with… – but wait, that’s for comparing. Instead, look for History in the context menu. If you see it, click it.
- If you don’t see History, go to File → Recent Files and Projects and look for the file name. If it appears, select it and then choose Restore.
If Local History is enabled, you will see a list of saved versions. Select the one from before the deletion and click Restore. The file will be recreated in its original location.
If you don’t see History, Local History might be disabled. To enable it: Tools → Options → Text Editor → General and check Track changes and Auto-load if available. Note that Local History only tracks files that were part of an open solution, and it only keeps a limited number of versions (default is 50 per file).
Method 2: Recover from Source Control (Git or TFVC)
If your project uses Git (either locally or with a remote like GitHub or Azure DevOps), you can recover the deleted file from the repository history.
- Open the Git Changes window (View → Git Changes).
- Look for the deletion in the Changes list. If you haven’t committed the deletion yet, you can right-click the deleted file and choose Undo Changes to restore it.
- If you already committed the deletion, open the Git Repository window (View → Git Repository).
- Right-click the commit where the file was deleted and choose View Commit Details.
- In the details pane, find the deleted file, right-click it, and select Restore.
For TFVC (Team Foundation Version Control), the steps are similar: in Source Control Explorer, right-click the parent folder, choose View History, find the changeset that deleted the file, and then Rollback that changeset or use Get Specific Version to retrieve the file from an earlier version.
Method 3: Check the Project File and .vs Folder
If the file was not tracked by source control and Local History is off, there is still a small chance the content exists in the .vs folder of your solution. This folder contains temporary files and IntelliSense caches. It is not a guaranteed recovery source, but sometimes the file content is cached in a .suo or in the FileContentIndex folder.
- Close Visual Studio.
- Navigate to your solution folder. Look for a hidden folder named
.vs. - Inside, look for a subfolder named
FileContentIndex(orv17depending on version). This folder contains a database of file contents. - You can try to search for a unique string from your deleted file using a text search tool (like grep or Windows Search) inside that folder. If you find a match, you can copy the content out.
This method is hit-or-miss, but it has worked for some developers. The .vs folder is often deleted when you clean the solution, so it’s not a reliable backup.
Method 4: Use Windows File Recovery or Third-Party Tools
If none of the above work, the file may still be recoverable from the disk itself, provided the disk space has not been overwritten. Windows 10 and 11 include a command-line tool called Windows File Recovery (winfr). It is not installed by default; you can install it from the Microsoft Store.
- Install Windows File Recovery from the Microsoft Store.
- Open Command Prompt as Administrator.
- Run:
winfr C: D:\Recovery /regular /n ".cs"(replace C: with your source drive and D:\Recovery with a destination folder on a different drive). - Wait for the scan to complete. It may take a long time.
Third-party tools like Recuva or Disk Drill can also recover deleted files, but they are not free (some have free trials). They work by scanning the raw disk sectors. The sooner you stop using the drive, the better the chance of recovery.
Prevention: How to Avoid This in the Future
The best way to recover a deleted file is to never need to. Here are some habits that help:
- Commit to source control regularly – even a local Git repository is a safety net. Commit at least daily.
- Enable Local History – it is on by default, but make sure you haven’t disabled it.
- Use the Recycle Bin for manual deletions – if you delete files via File Explorer instead of Visual Studio, they go to the Recycle Bin.
- Use a cloud backup – OneDrive, Google Drive, or a backup service that keeps version history.
- Be careful with the Delete key – in Solution Explorer, the Delete key deletes the file permanently. If you want to remove it from the project but keep it on disk, use Exclude From Project (right-click → Exclude From Project).
Frequently Asked Questions
Can I recover a file deleted in Visual Studio from the Recycle Bin?
No. Visual Studio does not use the Recycle Bin for file deletions. The file is removed from the disk immediately. The only way to recover it is through Local History, source control, or a disk recovery tool.
Does Visual Studio have an undo delete feature?
There is no direct “undo delete” for files in Solution Explorer. However, if you delete a file and immediately press Ctrl+Z, in some versions it may restore it, but this is not reliable. The safest is to use the methods above.
How long does Local History keep deleted files?
Local History keeps a limited number of versions (default is 50 per file) and they are stored for a limited time (default is 30 days). After that, they are purged. You can adjust these settings in Tools → Options → Environment → Documents.
If I use Git, can I recover a file that was never committed?
If the file was never committed, Git does not have it. However, if you staged it (git add), it might be in the Git object database for a while. You can try git fsck --lost-found to find dangling blobs, but this is advanced and not always successful.
Is it safe to use a third-party recovery tool?
Yes, but stop using the drive immediately to avoid overwriting the deleted file. Use the tool on a different drive if possible. Free tools often have limitations on file size or number of files, but they can work for a single file.
What if the file was in a web project or a non-C# project?
The methods above work for any file type in Visual Studio, including .js, .css, .html, .config, etc. Local History and source control are not language-specific.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.