rex
rex

Reputation: 3183

How to add files and folders to program directory in .NET?

I'm writing a winforms application in C#. I want to have some folders (and potentially some files) always in my program's ('install') directory which I will be using in the application. Potentially moving these when I deploy the app on different machines. I also need these to be present when I am writing, compiling and testing the programme obviously.

How can I do this without writing code to create these folders on programme startup?

Upvotes: 0

Views: 127

Answers (2)

user3427376
user3427376

Reputation: 31

To copy a directory, go to Project->Properties->Build Events and add this:

XCOPY "$(SolutionDir)Resources\MyDir" "$(TargetDir)\MyDir\" /S /Y

"/S" will copy files recursively, and "/Y" will overwrite without prompt.

Upvotes: 0

Sudhakar Tillapudi
Sudhakar Tillapudi

Reputation: 26209

You can add whatever files you want to work with in your project and then set the

Copy to Output Directory property of the files to Copy always option.

so that the files willbe always copied to your output directory either bin/Debug or bin/Release and you can always access them.

Upvotes: 2

Related Questions