Reputation: 3
I have project in VS 2010 with XML file. I want to read it but in debug mode I receive error file not found? How I can tell VS copy it to Debug folder?
Upvotes: 0
Views: 3317
Reputation: 20320
There's a few ways to do. If the xml is part of your project you should add it, and then in the properties set it to copy always, copy if newer.
You could also add it as a resource, you'd have to change the way you read it then as it would no longer be in a file, but compiled in the exe / dll. Has the advantage, in that it can't be missing, but if you want to change it, you have to recompile. Some times VS gets a bit iffy about that, and you might want to do Clean solution, to make sure it compiles in the latest version.
Put the path to the file and it's name in a config file, possibly with some admin style dialog to look it up you can kick off it's it's not there or not set.
Last but not least leave that lot until you know more, and just copy it in to your bin/debug directory.
Upvotes: 0
Reputation: 205
Right click on the file in the Solution Explorer, choose Properties then set "Copy to Output Directory" to "Copy Always".
This will copy the file into the build folder every time you build the project.
Upvotes: 2