Where does Visual Studio search for txt files when conducting file management operations?

后端 未结 4 2066
攒了一身酷
攒了一身酷 2020-12-20 15:00

I know this is a noob question, but I\'ve worked with Python before and when you wanted to simply access a .txt file for example, all you had to do was make sure the txt fil

相关标签:
4条回答
  • 2020-12-20 15:35

    Visual Studio sets the working directory to YourProjectDirectory\Debug\Bin when running in debug mode. If your text file is in YourProjectDirectory, you need to account for that difference.

    The easiest way to do that is to include your text files in the project and set their build action (in the Properties window) to Content.

    0 讨论(0)
  • 2020-12-20 15:43

    If you're talking about running the code within the Visual Studio debugger via F5 or Debug / Start Debugging, you can set the working directory of your program via Project / <Project name> Properties / Configuration / Debugging / Working directory.

    Put your text file in a directory somewhere, and set Working directory to point to that directory.

    0 讨论(0)
  • 2020-12-20 15:45

    I just had this same problem, and I didn't find any of those answers to work. Then I remembered what I learned a long time ago in OOP. What you have to do is take that text file on your desktop, and find the project folder in your visual studio projects within your computers documents, and put the text file in that folder outside of visual studio. Then in visual studio under source files, right click-> add existing item->(your text file)

    :)

    btw I bumped this thread because this thread said it was a good idea, and I wanted it updated for the sake of people googling the same question. https://meta.stackexchange.com/questions/125965/is-bumping-old-questions-allowed

    0 讨论(0)
  • 2020-12-20 15:51

    Working path is project directory.

    0 讨论(0)
提交回复
热议问题