How to find sub-folders of application?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All,

This is sure to be an easy question.

I am wondering what the accepted standard is for referencing a sub-folder
below the application.exe folder? In VB6 you simply used App.Path and
navigated from the folder indicated. In .Net, however, when running through
the IDE, this seems to return either the ...bin/debug or ...bin/release
folder - in which case the 'sub-folders' are actually to be found in the
.../../ folder.

What is the best way to find a folder beneath the .csproj folder to ensure
the code works at design/release and executable time?

Regards,
Rob
 
Actually, the "bin/debug" is correct, as far as the system is concerned.
Remember that when the code is compiled, it copies all binaries into the
"bin/debug" (or "release") and then executes from there. To be consistent
with how you deploy your information, you will need to copy all other
artifacts to this folder. I have always thought this to be an annoying
"feature" in VS.NET.
 
Robert Magnusson said:
Hi All,

This is sure to be an easy question.

I am wondering what the accepted standard is for referencing a sub-folder
below the application.exe folder? In VB6 you simply used App.Path and
navigated from the folder indicated. In .Net, however, when running through
the IDE, this seems to return either the ...bin/debug or ...bin/release
folder - in which case the 'sub-folders' are actually to be found in the
../../ folder.

What is the best way to find a folder beneath the .csproj folder to ensure
the code works at design/release and executable time?
<snip>

Rob, for C#, look up the help on Application.StartupPath. I imagine it would
be similar for VB.NET.

HTH

Ron.
 
Ron,

Application.StartupPath returns the bin\Debug folder when running through
the VS IDE. When installing the application on a clients machine I'd put the
exe in the 'root' folder and then have sub-folders beneath this (so
Application.StartupPath would work at this stage). The problem I am trying
to get around (elegantly) is that the application (through the IDE) always
ends up in the bin/Debug folder so relative paths (from in this case the
csproj) are actually ../.. from the exe at design time. This may mean that I
have to have design-time specific code to handle the relative paths and
'production' code to handle it when running the exe. Sounds a bit draconian
to me.

Rob
 
Hi!

I recently have written such function, probably it that you search.

public string DoRoutine(string Path, int xxx)
{
if (xxx != 1)
{
aFolders.Add(@Path + @"\");
}
DirectoryInfo di = new DirectoryInfo(@Path);
DirectoryInfo[] diArr = di.GetDirectories();
foreach (DirectoryInfo dri in diArr)
{
aFolders.Add(@dri.FullName + @"\");
DoRoutine(@dri.FullName, 1);
}
return null;
}

Try:

ArrayList aFolders = new ArrayList();

DoRoutine(Application.StartupPath, 0);

or remove a line:
DoRoutine(@dri.FullName, 1);
 
Gentlemen,

My quandary seems very similar to what's being discussed and I'm hoping one
of you can help;

At the top level of my project I have a folder called "Graphics". Inside
this I have a number of image files. They're all loaded (referenced) in the
Visual Studio Solution Explorer yet when I actually run the code (on a Pocket
PC) the image files all get copied to the same folder as the EXE. What I
want instead is for Graphics\*.* to be copied.

What am I doing wrong?

--
Robert W.
Vancouver, BC
www.mwtech.com



Kostya Ergin said:
Hi!

I recently have written such function, probably it that you search.

public string DoRoutine(string Path, int xxx)
{
if (xxx != 1)
{
aFolders.Add(@Path + @"\");
}
DirectoryInfo di = new DirectoryInfo(@Path);
DirectoryInfo[] diArr = di.GetDirectories();
foreach (DirectoryInfo dri in diArr)
{
aFolders.Add(@dri.FullName + @"\");
DoRoutine(@dri.FullName, 1);
}
return null;
}

Try:

ArrayList aFolders = new ArrayList();

DoRoutine(Application.StartupPath, 0);

or remove a line:
DoRoutine(@dri.FullName, 1);



Robert Magnusson said:
Ron,

Application.StartupPath returns the bin\Debug folder when running through
the VS IDE. When installing the application on a clients machine I'd put the
exe in the 'root' folder and then have sub-folders beneath this (so
Application.StartupPath would work at this stage). The problem I am trying
to get around (elegantly) is that the application (through the IDE) always
ends up in the bin/Debug folder so relative paths (from in this case the
csproj) are actually ../.. from the exe at design time. This may mean that I
have to have design-time specific code to handle the relative paths and
'production' code to handle it when running the exe. Sounds a bit draconian
to me.

Rob
 
Back
Top