Groups | Blog | Home
all groups > c# > july 2005 >

c# : How to find sub-folders of application?


Robert Magnusson
7/9/2005 9:30:01 PM
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,
Peter Rilling
7/10/2005 12:32:50 AM
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" <RobertMagnusson@discussions.microsoft.com> wrote in
message news:63EF111D-CA3D-4A16-B81B-307BA352E4EA@microsoft.com...
[quoted text, click to view]

Robert Magnusson
7/10/2005 2:52:14 AM
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

[quoted text, click to view]
Ron
7/10/2005 8:40:07 AM
"Robert Magnusson" <RobertMagnusson@discussions.microsoft.com> wrote in
message news:63EF111D-CA3D-4A16-B81B-307BA352E4EA@microsoft.com...
[quoted text, click to view]
<snip>

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

HTH

Ron.

Kostya Ergin
7/10/2005 2:24:18 PM
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" <RobertMagnusson@discussions.microsoft.com> wrote in
message news:AB480E5C-85DC-4F16-8F97-4B8C23A85A60@microsoft.com...
[quoted text, click to view]

Robert W.
7/18/2005 1:56:10 PM
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



[quoted text, click to view]
AddThis Social Bookmark Button