0

From comments I now know that .cs file get compiled and are not really in the exe, so this post is on how to get the text from an txt content

------------------------------------------------------------------------

For example if I had a project that has a file named "ThisIsText.txt" inside it, could I be able to get the text from it? What about if it's a .cs C# file?

I know that you could get text with System.IO.File.ReadAllText, but that only works if the file exist, not when the program is compiled.

For example in img, could a C# console program just print out the Program.cs or ThisIsText.txt? enter image description here

Edit: The txt file build action is Content.

13
  • How does it have the file inside it? Commented Jun 5, 2020 at 6:48
  • How can one have value at compile time? Commented Jun 5, 2020 at 6:48
  • 1
    "What about if it's a .cs C# file" ...these get compiled, the raw .cs files are never added to the compiled executable. Are you really asking whether your application could be decompiled, so that someone else would be able to read the code or settings? The answer to that is, to some extent yes, .NET programs can be decompiled. You may not get out exactly what was put in, but it's possible that someone could understand some or all of it. People sometimes use obfuscation tools to try and minimise the risk of this. Commented Jun 5, 2020 at 6:54
  • 3
    OK, you've shown us a text file in a project. Now what is its build action? Content? Embedded resource? What? Note that if is just a file in the project (build action "none") then it won't be included in the compiled executable. Commented Jun 5, 2020 at 7:11
  • 1
    @John, Ahhh....now I'm getting the problem. Thanks, let me do a little googleing Commented Jun 5, 2020 at 7:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.