I have added a solution folder on my visual solution project. I have added some text files inside that folder.
I have Built and Rebuilt my solution but still nothing.
The error I get when trying to access a file from the folder:
System.IO.StreamReader file0 = new System.IO.StreamReader(Path.Combine(Environment.CurrentDirectory, @"newFolder\SampleText.txt"));
An unhandled exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll
Additional information: Could not find a part of the path 'I:\Programming\Projects\SampleProject\SampleProject\SampleProject\bin\Release\newFolder\SampleText.txt'.
The path to the Release folder is valid, but newFolder is not inside. I don't understand why it is not being generated, any help would be great.
The bin folder holds binary files, which are the actual executable code for your application or library. Each of these folders are further subdivided into Debug and Release folders, which simply correspond to the project's build configurations.
The simplest way of doing it is by adding the desired folder to your project and the exe file on the folder. Change the properties of the exe file to "Content" and "Copy always". By doing that, everytime you rebuild your solution, the output will have the folder and exe file.
"Copy to Output Directory" is the property of the files within a Visual Studio project, which defines if the file will be copied to the project's built path as it is. Coping the file as it is allows us to use relative path to files within the project.
Click on your text file, change Copy to Output Directory
to Copy if newer
or Copy always
. This will copy the file and any folder structure beneath it up to the project level and re-create it in the output folder.
The answers correct. You need to change "Copy to Output Directory" to "Copy Always" or "Copy If Newer" BUT YOU NEED TO DO ONE MORE THING. You need to choose Build Action as "Content". By doing so the folders that contain the files are generated in debug folder automatically without hassle. The other Build Actions may also work I am not sure but not "Resource" one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With