AdamM said:
How can an app detect whether its running under debug or release mode
and update file paths automatically?
I have several hardcoded paths like "c:\app\bin\debug" currently and
want to make it more robust.
Thanks!
Adam
Hi Adam,
use Application.StartupPath to determine the directory. Now there are
two ways (Well, actually there are some more
) to handle the paths:
->Make all you hardcoded paths relative to your application directory,
e.g.: ..\..\Data. Use Path.Combine to build a valid Path when you need it.
string path =
Path.GetFullPath(Path.Combine(
Application.StartupPath, @"..\..\Data")
);
->store all you data under thhe current or the all user profile. You can
get the path like this:
string curUserProfile =
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string allUserProfile =
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
You might want to evaluate to use the isolated storage mechanims, too.
HTH,
Andy