Hello, this is the project structure I have.
I am trying to get open a pipe.txt
in resources
with Program.cs
I am using Directory.GetCurrentDirectory()
however, it is states that the file is in the bin
.
I think it’s possible to place the folder in the bin
directory so that it may open, but before doing that, I am looking for relative alternatives
Try the following:
Click on the text file in your Solution Explorer.
Open the Properties window.
Set the Build Action to None (if it isn’t already).
Set the “Copy to Output Directory” to “Copy if newer” (or always if you want to).
This should place the file in the same relative location to the executable as it is to the Program.cs file in your Solution Explorer.
Try this article
https://stackoverflow.com/questions/52797/how-do-i-get-the-path-of-the-assembly-the-code-is-in
Hello, unfortunately this doesn’t work
When you run your program, the bin folder is the execution folder (that’s where your. exe is located). In order for your program to access the file “pipes.txt, it should be in the bin folder.
This how you acces the execution folder :
https://www.c-sharpcorner.com/blogs/how-to-get-application-startup-path-from-the-console-application-using-c-sharp
Hello, I think this is the correct answer.
C# devs
null reference exceptions