2

Yesterday while was writing code in model Repository suddenly power off. I left and when I open now Repository.cs was opening in notepad. Actually in Notepad it is empty.

Any way to recover the code as I don't have back up of my whole days work?

How to reopen it?

Yuliam Chandra
  • 14,494
  • 12
  • 52
  • 67
  • 1
    You definitely should start using source control in your project. It seems your file is damaged, you may try some file system recovery http://superuser.com/questions/518979/corrupt-ntfs-filesystem-how-to-recover-files-in-folder – Vojtěch Dohnal Sep 27 '14 at 06:47
  • 1
    Related: https://stackoverflow.com/questions/12968836/visual-studio-is-opening-web-page-in-notepad View also: https://luiscarrazana.wordpress.com/2016/05/19/aspx-file-opens-as-empty-notepad-from-visual-studio/ – Eric Levieil May 15 '18 at 21:42

4 Answers4

5

Try with this..
There are possibility for code loss when power breaks are there.. The primary solution is You can recover from back up files and add it with ur application. or If you have AutoRecovery enabled, you might be lucky enough to find a backup of the file. Chances are that Visual Studio would’ve prompted you to restore the corrupted file when launching it after the crash. Anyway it’s still worth checking the backup folder for your project, in:

%USERPROFILE%/Documents/Visual Studio [Version]/Backup Files/[Solution Name]

Other ways to recover

Recover the affected file in VS

Karan
  • 12,059
  • 3
  • 24
  • 40
KaviSuja
  • 450
  • 1
  • 9
  • 37
  • Whilst this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Manfred Radlwimmer Apr 24 '17 at 11:03
1

This thing recently happened with me, I also haven't any backup of my work and my laptop gone shut immediately after a lag. Then I restarted my Project Solution and it was same thing came to me, my CS file was opening again and again in Notepad. After some try i Got my data and file, let me Explain the Process, how i recovered my File :-

[Read Carefully]

Step 1 :- Right Click on your Root Folder into Solution Explorer.

Step 2 :- Click on -"Open Folder in file Explorer", Then your Solution will be open in the file explorer.

Step 3 :- then Right Click on the File like "Default.aspx.cs" which is opening into Notepad.

Step 4 :- Then Click on "Restore Previous Versions", and select the time you were Working and click on "Ok" Button.

Step 5 :- Now Go and See the file into your Solution, Your Data will be there,

Note :- if, after this all, the data doesn't come into the file, then refresh the folder.

Shubh
  • 11
  • 3
  • 1
    Hi Shubh: Thanks for the steps. It seems you are using some version control based on your step 4. It woud be more helpful to users if you could provide that version contol name too. – Ravi Kiran Ayinampudi Mar 03 '20 at 01:37
  • @Ravi Kiran, Dear sir, there is nothing like verion controlling, it's just a menu named "Previous Versions", means the solution in which you worked last time, that is the previous version – Shubh May 05 '20 at 10:41
0

Don't quote me on this. But you may try opening the entire project inside of VS2010 IDE, and it may be cached in there. I'm assuming you know how to open files with other programs.

Ben P. Dorsi-Todaro
  • 221
  • 1
  • 6
  • 20
  • Yeah in VS2010 IDE i opened.Remaining files are opening correctly except this Repository.It is bydefault opening in notepad. – Ravi Kiran Ayinampudi Sep 27 '14 at 06:32
  • Open up your command line and cd to the directory of the project. Then type dir. I'm thinking an extension may have been added onto end of it. Something like repository.cs.blah – Ben P. Dorsi-Todaro Sep 27 '14 at 09:03
-1

You can recover the file. Do this if anyone still having this issue.

1) Exclude the file from Solution Explorer(Right Click>>Exclude) 2)Include the file again (Right click in directory icon in Solution Explorer>>Add>>Add Existing Item)

You will have the file available in Visual Studio.

Hope this help

user786
  • 3,902
  • 4
  • 40
  • 72