In Visual Studio (VB.NET), I want to open a file and read the contents into a string. It’s easy enough when the file is in a known location on disk, since you can reference it as C:\Windows\foo.txt or whatever. Is there any way to refer to files based on their location in the solution? For example, MySolution\MyProject\MyFolder\foo.txt. The file to read will be a SQL file, so there won’t be any code objects in it to work with.
I use a whole bunch of different solutions that are stored in various places on disk, so I really don’t want to have to deal with the file system directly. Any ideas?
If you go to the file properties for the file in the solution, you’ll notice that one of the options is “Copy to Output Directory”. You need to set that to either “Copy always” or “Copy if newer”. Once you set that on all the pertinent files and re-build the project, you will notice that all of those files will be copied to the
bin\Debugorbin\Releasefolder (which ever one you were building to) as part of the build process. Now, in your application, you can just assume that they will be in the same directory as your application.