The Mysterious Case of Visual Studio Corruption (or how I learned to recover a corrupt .ascx file)


I had made a lot of progress on a new feature for one of our DNN modules. The majority of the implementation was in JavaScript with a few server side components. After adding in a bit more code, I hit CTRL+S to save my work (which I do frequently) and my computer immediately blue screened. Since I had just saved, I was not worried about losing any progress.

The computer did its thing..


We’ve all seen some form of this lovely screen

..and then transferred control back to me, I fired up Visual Studio, opened the project, and opened the .ascx file I had been working on and saw something I had never seen before:

Corrupted ASCX File

The Visual Studio matrix

The above image only contains part of the ascx file, the entire file had been overwritten with this! All of the code behind for the new feature was intact, but my markup and JavaScript were obviously absent from the file. I was devastated (you know, that fantastic feeling of your heart violently descending into your stomach).

I had spent a lot of time figuring out various APIs and methods for developing this new feature and had written quite a bit of JavaScript. If I had been capable of recalling every line of code I had written, this would not have been a big deal. However, the current version of my memory does not have that feature.

Visual Studio Backup

Visual Studio saves a backup of your files so I figured could use the backup to restore my .ascx file. All I needed was the JavaScript; the rest of the markup changes were quite simple so I could retrieve the rest from TFS.

To enable the Auto Recovery feature of Visual Studio (if is not already enabled) navigate to Tools > Options > Auto Recover (located in the Environment section)

AutoRecover settings

Visual Studio AutoRecover settings

Visual Studio back up files are stored in the Documents\Visual Studio {version}\Backup Files folder (in my case, Documents\Visual Studio 2012\Backup files – as you can clearly see in the screenshot).

Backup Folder

Visual Studio Backup Files folder


Temporary ASP.NET Files and the Recycle Bin

The project folder was in the Backup Files folder but the .ascx file was not there. Arrgh! I scoured through all of the temporary ASP.NET files and folders and found something. By something, I mean nothing.

Temporary ASP.NET files are located in C:\Windows\Microsoft.NET\Framework\<version>\Temporary ASP.NET Files so this was the next location searched.

Temporary ASP.NET files folder

Temporary ASP.NET files folder location


Windows File History

Windows (8, not sure about other versions) has a neat featured called File History that I could use to restore the file to a previous version.

Windows History

History never happened

Nope! The feature had not been enabled so there was no history to recover.

For others, here are a few helpful links:

Now What?

At this point I was angry, sad, frustrated, ready to accept that the work was gone and start over.

I searched the internet to see if others had encountered this mysterious .ascx file corruption. There were various suggestions and methods for recovering the code behind but nothing for recovering a corrupt .ascx file.

After an hour or two of searching, I forced myself to step away from the computer and take a break to eat some dinner. As I was furiously placing food into my mouth, I had an idea: I’d try completely deleting the file from the system and then recovering it using a data recovery program.

Yay! A Possible Solution

Before deleting the corrupt file, I created a copy of it. The file was deleted, sending it to the Recycle Bin and then from the Recycle Bin, I deleted it. Then I downloaded an application called Recuva* and ran its default scan, which did not find the file. Next, I ran the deep scan and it found the file! Recover file? You bet your .ascx I want to recover it.

*I do not want to be responsible for sending someone to a confusing “download now” page with fake buttons so the link to Recuva is not provided. Use your own discretion when searching for the downloadable file.

<insert witty title here>

Nervously, I sat staring at the file on my desktop. Please please please please…. I opened the file, woohoo, my markup and JavaScript were visible. There were a few minor restore errors in the file, but all of the JavaScript was exactly how I had left it. Relieved, I copied and pasted the JavaScript into a text file, saved it, and then undid all pending changes to that file and checked it in. After a get latest, I added my JavaScript back into the file and reveled in my accomplishment.

I never want to do that again.

Leave a Reply

Your email address will not be published. Required fields are marked *