38

I've just lost some code. I needed to move a couple of methods from one class to another so i hit save, cut the methods and VS crashed. Now it seems that the save happened after the cut since the code has been saved without those methods but the code isn't on my clipboard. So I'm left without the code and no easy way to get it back!

I know that Visual Studio keeps a document cache which it uses when the recover files dialog is shown but it wasn't shown when VS started back up. I'm hoping that there is a version of my class with the code still in there so i don't have to start again but i don't know where to look.

Can anybody tell me where VS keeps these files on disk?

Really appreciate ANY help you can offer.

Jeff Moser
  • 19,727
  • 6
  • 65
  • 85
EightyOne Unite
  • 11,665
  • 14
  • 79
  • 105

10 Answers10

80

Sorted it. Those recovery files are located @ MyDocuments\Visual Studio X\Backup Files\Project Name...

EightyOne Unite
  • 11,665
  • 14
  • 79
  • 105
  • 3
    Also nice to know (least with 2010) is that the recovered file & the original file are in the same folder, I just had a corupt 'recovered' file almost lose me 2 days worth of work (yet the original file was actually up to date...) – Stephen Nov 09 '11 at 16:30
  • 18
    did you have to enable this feature? my version of this folder is empty. – Brian Sweeney Nov 09 '12 at 17:40
  • 1
    This option is available in Visual Studio 2017, but not in Visual Studio 2019. – Evorlor Feb 07 '20 at 23:24
  • 1
    @BrianSweeney I believe this folder moved in the latest version. This answer below has the correct folder path now: https://stackoverflow.com/a/59277526/358578 – pbristow Jul 14 '20 at 18:01
  • Note that the 'X' here is the number of your MVS version. That saved me 1 day job today. – Marcello Silva Aug 06 '20 at 14:59
  • THANK GOD!!! Potentially HOURS worth of work lost!!! But recovered. THANK YOU. Visual Studio DID auto-save my files, but did NOT reopen the backups properly when I restarted it. Though I did have to search for my `Backup Files` folder. I'm using `SSIS` in VS 2019, but the backup files were in `%UserProfile%\Documents\Visual Studio 2017\Backup Files\Solution1`. To find the folder, I used a Command Prompt window with the following command: `dir "Backup Files" /s /b /ad`. Then sorted the temp files by date, and the one I was looking for was a couple files down. ♥ – spinjector Sep 12 '21 at 09:04
  • In my excited comment above I spoke incorrectly. The recovery was in `SSMS`, not `SSIS`. This may explain why the files were in VS2017 instead of VS2019. – spinjector Sep 12 '21 at 09:17
57

Visual Studio 2019.4.1 had my backup files in %localappdata%\Microsoft\VisualStudio\BackupFiles - the folders in the MyDocuments tree were empty.

CAD bloke
  • 8,578
  • 7
  • 65
  • 114
  • 3
    Thanks @CAD bloke, you saved my life. Vs2019 save the file twice, before recover as Original-$datetime$filename.cs and the recovered(which is damaged), then i restored the original file and restored non-committed work.. – M.Hassan Dec 29 '19 at 23:35
  • Man you saved one day of work with this hint! Thank you so much :-) – XavierAM Feb 07 '20 at 08:31
  • Happy to make a difference. So glad I could help. – CAD bloke Feb 07 '20 at 10:20
  • 1
    VS2019 did not autorecover this for me and I was able to dive in the tree and find my code. 2 hrs saved! – Hucker Feb 11 '20 at 13:14
  • 1
    Thank you, you saved my life. Everytime I allow visual studio to revocer some data for me, it mess things bayound recovery. but this time it currupt several days worth of job, and i couldn't stand it, tried decompiling, searching, hidden files, any thing, and in the end you saved my time. thank you. – Hassan Faghihi Apr 25 '20 at 15:00
  • 2
    Saved me from a heart-attack when a VS backup recovery wiped a really important file clean.. I will forever thank you! – Brixster May 05 '20 at 20:23
  • 2
    Man, you saved me from a heart attack! – SexyBeast Jul 12 '20 at 22:30
  • Thank you. The VS documentation agrees with the most upvoted answer here, but the folder doesn't exist there for 2019. How you found this is beyond me. – pbristow Jul 14 '20 at 17:55
  • @pbarranis I grepped %localappdata% for some text that went missing. Also, it was more of a hunt than a search, I was fricken angry. – CAD bloke Jul 21 '20 at 12:18
  • 1
    @CADbloke I submitted your info as a correction to VS Docs, which is why they are now corrected. Nice work for finding them. – pbristow Aug 15 '20 at 11:52
  • Thanksssssssssssssss – Sayed Mahmoud Sep 28 '20 at 15:32
  • Sadly my directory was empty, any advice? (VS periodically just doesn't save the file despite the * going away. – Reahreic Oct 13 '20 at 15:06
  • @Reahreic Check the auto save etc settings are ok and the save locations are legit. Try grappling the docs & temp folders, you never know your luck. If the folder is roamed on a network or some cloud service that may have something in its history or may be interfering. – CAD bloke Oct 13 '20 at 19:42
  • Saved me too. Thanks a lot :) – skm Dec 15 '21 at 09:38
12

If you have compiled the code into a DLL, then you can use ILSpy, or Reflector to decompile that back into code.

RB.
  • 36,301
  • 12
  • 91
  • 131
8

I came here looking for an answer to the same issue, but none of these things helped -- that being said, in visual studio 2010 deleted files end up in the Windows Recycle bin.

Here's another post talking about the same thing: How do I recover a deleted item from Visual Studio 2010?

Community
  • 1
  • 1
aradil
  • 492
  • 7
  • 12
2

This is a known bug in VS and is being continually ignored by Microsoft. I've lost full day's worth of work as a result. The solution that worked for me was to move my project to a GoogleDrive sync folder. Now every time I save files, Google drive syncs a copy to the cloud. Along with regular commits to Git, I should never have to loose work.. sigh

redditmerc
  • 125
  • 1
  • 6
2

For Linux, the location seems to be ~/.config/Code/Backups/

(found the info here: https://github.com/Microsoft/vscode/issues/3884)

Good luck recovering your files, future travellers! I got lucky!

fahran
  • 153
  • 1
  • 6
1

It doesn't help you now, but you might want to install ClipX, which helps keep as many items on the clipboard as you'd like. It's helped me in times when the crash happened, but there was a version on the clipboard awhile back.

Jeff Moser
  • 19,727
  • 6
  • 65
  • 85
0

Running on Ubuntu 18.04, with VS code 1.51.0

My VS Code deleted files are located at: ~/.local/share/Trash/files

To search for your deleted files:

find ~/.local/share/Trash/files -name your_file_name 

Hope my case helped!

Yuanjing Cai
  • 181
  • 1
  • 3
0

For those finding this after deleting files and using Visual Studio (2019, professional in my case) and none of the above working, I managed to find some intellisense backups in:

%appdata%\Local\Temp\VSFeedbackIntelliCodeLogs\Suggestions\XXX\output\versions

Where XXXX is the nearest time in which you were working on the deleted files.

One of my missing files was there in it's entirety, another did have some bits missing but it's far better than the alternative.

0

It's actually simple. Open Command Pallette in VS code by Typing Ctrl Shift P, Mac I assume cmd Shift P. Then search "local history" you should see revert entry ... then a pop up will show up select the file to revert. You will see the code there.