Recover a .CS class file after crash

Something which worked for me was back-up. BTW I was trying to recover a VS2013 file on a Windows 8 machine.

Try to check in below location in your system.

C:\Users\username\My Documents\Visual Studio \Backup Files\ProjectFolder

I found an original file with original-date.filename.cs name and a recovered-date.filename.cs files.

The original was the one needed. Deleted the one in project, added the original file and renamed it to file.cs. Tried building and debugging and it gave the expected results.


Also just want to add one more thing... In my case i had an aspx page with its respective .cs and designer.cs The .cs file got corrupted and I did build on project, with the designer.cs the project got build successfully and the dll got replaced. And when i tried to recover using reflector everything was in a state no return. :(

So don't build the project if you see any file got corrupted.


If you cannot find the source code file, try using Reflector to decompile the most recently built dll you have containing that class. It won't give you your complete source, but at least will give you something to start with.

Note: Reflector is no longer free; if that matters, try dotPeek from JetBrains instead.

Also, look into using a source code control system. This will let you 'commit' versions of your code to a repository, so you'll have a copy in case something like this happens in the future.

Subversion, Git, and Mercurial are popular ones; In my opinion, Subversion would be the easiest to start out with, especially with TortoiseSVN (OS integration) and AnkhSVN (Visual Studio integration). If you don't want to worry about setting up a repository/server, look into a hosted solution, like Beanstalk, which offers Subversion and Git and lets you try it out with a free, limited account.

Good luck - I hope you are able to recover your source!