tags:

views:

178

answers:

4

I need some help with paths please!

Basically I have a project with the following folder structure:

Project (root directory which contains the .sln file etc.)
Project/MyProj (contains the code)
Project/MyProjTest (the test folder)
Project/TestResults

Now with this Project I need to have a common folder where I can stick a bunch of files for use with the Application without having to copy the files to multiple locations etc. What is the best way to do this? Ideally I would like to have the folder as Project/ResourcesFolder, so that both the Code folder and Test folder can access it. Now if this is the case how do I call this folder from within C#? I've tried Application.StartupPath, Environment.GetCurrentDirectory but they both just return the CURRENT folder which is not what I want.

Thanks in advance.

+1  A: 

You can add a solution folder to your solution and place common files in it.

Oded
A: 

.. goes one directory up. That is, from Project/MyProjTest you could access Project/MyProj via ../MyProj.

phimuemue
But what if I needed to access the common folder from Project/MyProjTest AND Project/MyProjTest/SomeOtherFolder ?
Suraj
A: 

Use Server.MapPath("~") to get to the root folder of your application. From there you can get to wherever you need.

jvenema
+1  A: 

You'll have to copy the files, you'll want your program to operate the same way after it is deployed. The simplest way to do so is by adding them to your project. In the Properties window, set Build Action = None, Copy to Output Directory = Copy if Newer. The latter setting ensures that you don't waste time copying the files over and over again.

This ensures that the files will be present in the same directory as your EXE. Both when you debug and after you deploy it. Simply use Application.StartupPath to locate them. Creating the Setup project for the app is now very simple as well.

Note that if the files are small you really want to embed them as resources.

Hans Passant