1

I published a website few months ago and lost my local project. I can see all the files on my web server but I am not able to see the .cs files which are working as "CodeBehind". How to find the .cs files on the server?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Tudor Rose
  • 51
  • 1
  • 5

1 Answers1

4

If you used the Publish in Visual Studio, the .cs files won't be there. Instead, they will have been compiled, and you'll have some .dll files in your \bin directory.

If you need to get your original source code files back, you can use RedGate's Reflector or a similar tool to decompile the .dlls. The code won't be EXACTLY the same, but it will be usable. See this post : How do I decompile a .NET EXE into readable C# source code?

(And hopefully you didn't use an obfuscator.)

In the future if you want to preserve the actual .cs files, rather than use the "Publish" option, use Visual Studio 2010's "Copy website" option.

See different methods of deploying a website and their implications here.

Finally, I did manage to find an old 4Guys article on using Reflector here.

Community
  • 1
  • 1
David
  • 72,686
  • 18
  • 132
  • 173
  • Thank you David. Actually I am using an Online booking system developed using Asp.net Web service. And it was developed by another developer of our company and he's no more working with us. He was working in his laptop and he published in the same way as u said. I have the .dll files but I want to edit the user interface by inserting one more control/feature. So your answer is quite helpful thanks for the one but can you guide me some more on this please? I am a bit new to ASP.net anyway! Thanks a lot. – Tudor Rose Aug 31 '12 at 21:40
  • That would be a long topic, but here's where to start: Get the Trial version of Reflector. It should include help files, but it's only good for 30 days. Then get the aspx pages AND the conents of the \bin directory. Upen Reflector, and ther is an option to browse out to a .dll to "add" it. ONce you do that, I forget the commands - I haven't used it in a while, but you can decompile and you will see the C# code in a windows, which you can use to reconstruct the original .cs file. – David Aug 31 '12 at 21:47
  • I found an old article here. It should help. Things may have changed a bit, but it's basically the same as it is now. http://www.4guysfromrolla.com/articles/080404-1.aspx – David Aug 31 '12 at 21:50
  • I will have a look on it and will surely reply. You are so helpful Thanks again. :) – Tudor Rose Aug 31 '12 at 21:51
  • That's why the site is here. Welcome to the site, and good luck! – David Aug 31 '12 at 21:54
  • David I've one more question to ask you. I have found the files now.. but after editing the relevant files I end up with the following error: "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS." Can you please let me know what should be the problem? Because there are no Warning, no issues, it's just one error. Please. Thank you in advance. – Tudor Rose Sep 10 '12 at 09:06